• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JQuery Ajax Call to Servlet  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a button that should do an Ajax call to a servlet in order to create/write a Textfile in a certain Directory. How do i transfer the variable "text" to the servlet and does the Ajax call look right?





 
Marshal
Posts: 67225
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Two things about your Ajax call:
  • You've hard-coded the URL to use localhost. That means it cannot work anywhere else but your local machine. You should be using a URL that works everywhere. In order to help you figure out what that is, we need some more context. Since you mention Servlets, I assume that this is a Java web application in which the view is provided by a JSP in the same web app? If so, see below. If not, tell us what you've got going on.
  • The data is malformed. It cannot just be a string. See the description of the expected data format in the jQuery documentation for the $.ajax function.

  • In a Java web application, URLs into the same app should be server-relative, starting with the context path. See the JspFaq on resource URLs to learn how to create such URLs in JSPs.
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!