• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

JQuery Ajax Call to Servlet  RSS feed

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?

Posts: 67255
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.
    Did you just should on me? You should read this tiny ad:
    global solutions you can do in your home or backyard
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!