Send POST data using XMLHttpRequest

前端 未结 13 1426
说谎
说谎 2020-11-21 04:27

I\'d like to send some data using an XMLHttpRequest in JavaScript.

Say I have the following form in HTML:

<         


        
13条回答
  •  野的像风
    2020-11-21 04:49

    I have faced similar problem, using the same post and and this link I have resolved my issue.

     var http = new XMLHttpRequest();
     var url = "MY_URL.Com/login.aspx";
     var params = 'eid=' +userEmailId+'&pwd='+userPwd
    
     http.open("POST", url, true);
    
     // Send the proper header information along with the request
     //http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     //http.setRequestHeader("Content-Length", params.length);// all browser wont support Refused to set unsafe header "Content-Length"
     //http.setRequestHeader("Connection", "close");//Refused to set unsafe header "Connection"
    
     // Call a function when the state 
     http.onreadystatechange = function() {
        if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);
        }
     }
     http.send(params);
    

    This link has completed information.

提交回复
热议问题