Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

post data from api using jquery ajax

var myKeyVals = { A1984 : 1, A9873 : 5, A1674 : 2, A8724 : 1, A3574 : 3, A1165 : 5 }



var saveData = $.ajax({
      type: 'POST',
      url: "someaction.do?action=saveData",
      data: myKeyVals,
      dataType: "text",
      success: function(resultData) { alert("Save Complete") }
});
saveData.error(function() { alert("Something went wrong"); });
Comment

javascript ajax post send an object

function postAjax(url, data, success) {    var params = typeof data == 'string' ? data : Object.keys(data).map(            function(k){ return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) }        ).join('&');
    var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");    xhr.open('POST', url);    xhr.onreadystatechange = function() {        if (xhr.readyState>3 && xhr.status==200) { success(xhr.responseText); }    };    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');    xhr.send(params);    return xhr;}
// example requestpostAjax('http://foo.bar/', 'p1=1&p2=Hello+World', function(data){ console.log(data); });
// example request with data objectpostAjax('http://foo.bar/', { p1: 1, p2: 'Hello World' }, function(data){ console.log(data); });
Comment

PREVIOUS NEXT
Code Example
Javascript :: this.setstate is not a function 
Javascript :: 2nd highest number from array 
Javascript :: get list of all attributes jqery 
Javascript :: javascript rock paper scissors 
Javascript :: angular remove index of array 
Javascript :: how to write a program that shows a random number between 1 and 100 in your browser 
Javascript :: momentjs 
Javascript :: convert inches to feet javascript 
Javascript :: javascript redirection 
Javascript :: filter in js 
Javascript :: jquery datatable passing of parameters 
Javascript :: conditional jsx property 
Javascript :: state hook is not updating react 
Javascript :: javascript on selected 
Javascript :: react native password strength 
Javascript :: loop object array 
Javascript :: using ejs with express 
Javascript :: javascript detect scroll wheel 
Javascript :: javaScript getDay() Method 
Javascript :: how to compare two arrays javascript 
Javascript :: mongoose connect to atlas 
Javascript :: how to convert a string to react element in javascript 
Javascript :: js array.splice first element 
Javascript :: javascript object loop 
Javascript :: react - min & max for dates 
Javascript :: make random letter capital in string javascript 
Javascript :: get in redis 
Javascript :: javascript The replace() method 
Javascript :: axios api post request 
Javascript :: document fragment 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =