1var formData = {name:"John", surname:"Doe", age:"31"}; //Array
2
3$.ajax({
4 url : "https://example.com/rest/getData", // Url of backend (can be python, php, etc..)
5 type: "POST", // data type (can be get, post, put, delete)
6 data : formData, // data in json format
7 async : false, // enable or disable async (optional, but suggested as false if you need to populate data afterwards)
8 success: function(response, textStatus, jqXHR) {
9 console.log(response);
10 },
11 error: function (jqXHR, textStatus, errorThrown) {
12 console.log(jqXHR);
13 console.log(textStatus);
14 console.log(errorThrown);
15 }
16});
1<script type="text/javascript">
2 function send() {
3 var person = {
4 name: $("#id-name").val(),
5 address:$("#id-address").val(),
6 phone:$("#id-phone").val()
7 }
8
9 $('#target').html('sending..');
10
11 $.ajax({
12 url: '/test/PersonSubmit',
13 type: 'post',
14 dataType: 'json',
15 contentType: 'application/json',
16 success: function (data) {
17 $('#target').html(data.msg);
18 },
19 data: JSON.stringify(person)
20 });
21 }
22</script>
1$.post( "test.php", { name: "John", time: "2pm" })
2 .done(function( data ) {
3 alert( "Data Loaded: " + data );
4 });
5
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"); });
1$.ajax({
2 method: "POST",
3 url: "some.php",
4 data: { name: "John", location: "Boston" }
5})
6
7
1<script>window.onload = function(){
2 let aData = {"profile": "developer", "to": "rashid.jorve@live.in"};
3 console.log(FormData);
4 $.ajax({
5 type: "POST",
6 url: "/api/saveProfile",
7 data: JSON.stringify(aData),
8 contentType: "application/json",
9 success: function(){
10 alert("Request was successful");
11 }
12 });
13};