Answers for "send javascript array post ajax"

2

javascript send post data with ajax

function makeRequest (method, url, data) {
  return new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();
    xhr.open(method, url);
    xhr.onload = function () {
      if (this.status >= 200 && this.status < 300) {
        resolve(xhr.response);
      } else {
        reject({
          status: this.status,
          statusText: xhr.statusText
        });
      }
    };
    xhr.onerror = function () {
      reject({
        status: this.status,
        statusText: xhr.statusText
      });
    };
    if(method=="POST" && data){
        xhr.send(data);
    }else{
        xhr.send();
    }
  });
}

//POST example
var data={"person":"john","balance":1.23};
makeRequest('POST', "https://www.codegrepper.com/endpoint.php?param1=yoyoma",data).then(function(data){
              var results=JSON.parse(data);
});
Posted by: Guest on August-02-2019
0

how to send js array from ajax

$.ajax({
            type: "POST",
            url: "submit",
            data: ({detailsArr : detailsArr }),
            success: function(html){
              alert( "Submitted");
                }
          });
Posted by: Guest on November-24-2020
-2

how to send js array from ajax

$.ajax({
            type: "POST",
            url: "submit",
            data:JSON.stringify(detailsArr),
            success: function(html){
              alert( "Submitted");
                }
          });
Posted by: Guest on November-24-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language