0

I need to pass javascript variable "textVal" to a jsp.I just can't figure correct syntax. My code is like this

 function show(textVal){
   AJAX.onreadystatechange = handler;
   AJAX.open("POST","service.jsp",true);
   AJAX.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   AJAX.send("fname='+textVal+'");
};

How do i pass this textVal to service.jsp

5
  • If you are able to use jQuery, I would strongly recommend it, as ajax functionality is one of the areas where jQuery shines. Commented May 21, 2013 at 15:18
  • That's not how AJAX works. developer.mozilla.org/en-US/docs/AJAX/Getting_Started Commented May 21, 2013 at 15:18
  • @SLaks What's wrong with the code? Looks fine to me except for the param passed to .send() Commented May 21, 2013 at 15:20
  • @Ian: AJAX is not defined? Commented May 21, 2013 at 15:34
  • 1
    @SLaks Exactly, what is AJAX? It's probably not safe for me to assume it's an XMLHttpRequest instance, but it's also not safe to assume it's not. They seem to have the basics down - using onreadystatechange, open, setRequestHeader, and send properly. It might've been easier to ask and figure out what AJAX was instead of thinking they know nothing Commented May 21, 2013 at 15:38

1 Answer 1

3

You do not need the extra quotes. You can use:

AJAX.send("fname="+encodeURIComponent(textVal));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.