javascript - Send Custom HTTP Body with AJAX POST request -


how send custom http body post ajax request in plain javascript (not jquery)? trying send json file in body. can set custom header fields can't find how set http body.

below code

function calculateorder() {      document.getelementbyid("finalize").style.display = "inline";      url1 = "https://ethor-prod.apigee.net/v1/stores/";         url2 = "/orders/calculate?apikey=wsgbv9pe8ajhdoi17vvtux1nlaceuxg7";      url = url1 + store_id + url2;      var xmlhttp;     xmlhttp = new xmlhttprequest();      xmlhttp.onreadystatechange = function() {         if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {             alert(xmlhttp.responsetext);         }     }      xmlhttp.open("post", url, true);     xmlhttp.setrequestheader("content-type", "application/json");     xmlhttp.send(json.stringify(calculate)); } 

when used same headers , json file rested (a osx http client) works perfectly

add parameter in xmlhttprequest obeject's .send() method

like this:

xhr.send('username=me'); 

send json format data mydata this:

xhr.send(json.stringify(mydata)); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -