1

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.readyState == 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

2 Answers 2

2

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
1

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.

1
  • chuckle... but good work! I always like programmers who keep trying to solve their problem even after asking a question... instead of simply waiting for an answer... however trivial the issue may be.
    – Senthil
    May 27, 2010 at 8:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.