ajax strange error with sending multiple parameter
please check with me where is the error in this ajax code to send 2 parameters:
var xhr = getXhr();
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyS开发者_JAVA百科tate == 4 && xhr.status == 200)
{
selects = xhr.responseText;
// On se sert de innerHTML pour rajouter les options a la liste
//document.getElementById('prjsel').innerHTML = selects;
}
};
xhr.open("POST","ServletEdition",true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
id=document.getElementById(idIdden).value;
fu=document.getElementById("formUpdate").value;
//alert(fu);
var i=1;
xhr.send("id=" +id+", fu="+i);
i cant got the value of fu i don't know why. thanks
The contents of your xhr.send() need to be URL encoded. For example:
xhr.send("id=1&fu=2");
Basicallly, anything that goes inside the xhr.send() would be the same as the query string you'd set with a GET. In other words, what you have inside send should also work on the end of a URL:
http://www.mysite.com/path/to/script?id=1&fu=2
it is really strange because i am used to work with it like that. so i changed to the next:
xhr.send( "id="+id+"&fu="+i);
and it works.
thanks for help.
精彩评论