通过AJAX将javascript变量传递给JSP

时间:2013-05-21 15:16:12

标签: javascript ajax

我需要将javascript变量“textVal”传递给jsp.I只是无法想出正确的语法。我的代码就像这样

 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+'");
};

如何将此textVal传递给service.jsp

1 个答案:

答案 0 :(得分:3)

您不需要额外的报价。您可以使用:

AJAX.send("fname="+encodeURIComponent(textVal));