1$.ajax({
2 url: 'ajaxfile.php',
3 type: 'post',
4 data: {name:'yogesh',salary: 35000,email: 'yogesh@makitweb.com'},
5 success: function(response){
6
7 }
8});
1function makeRequest (method, url, data) {
2 return new Promise(function (resolve, reject) {
3 var xhr = new XMLHttpRequest();
4 xhr.open(method, url);
5 xhr.onload = function () {
6 if (this.status >= 200 && this.status < 300) {
7 resolve(xhr.response);
8 } else {
9 reject({
10 status: this.status,
11 statusText: xhr.statusText
12 });
13 }
14 };
15 xhr.onerror = function () {
16 reject({
17 status: this.status,
18 statusText: xhr.statusText
19 });
20 };
21 if(method=="POST" && data){
22 xhr.send(data);
23 }else{
24 xhr.send();
25 }
26 });
27}
28
29//POST example
30var data={"person":"john","balance":1.23};
31makeRequest('POST', "https://www.codegrepper.com/endpoint.php?param1=yoyoma",data).then(function(data){
32 var results=JSON.parse(data);
33});
1var myKeyVals = { A1984 : 1, A9873 : 5, A1674 : 2, A8724 : 1, A3574 : 3, A1165 : 5 }
2
3
4
5var saveData = $.ajax({
6 type: 'POST',
7 url: "someaction.do?action=saveData",
8 data: myKeyVals,
9 dataType: "text",
10 success: function(resultData) { alert("Save Complete") }
11});
12saveData.error(function() { alert("Something went wrong"); });
13