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$.ajax({
2 method: "POST",
3 url: "some.php",
4 data: { name: "John", location: "Boston" }
5})
6
7
1$.post('http://example.com/form.php', {category:'client', type:'premium'}, function(response){
2 alert("success");
3 $("#mypar").html(response.amount);
4});
1<!DOCTYPE html>
2<html>
3<body>
4
5<h1>The XMLHttpRequest Object</h1>
6
7<p id="demo">Let AJAX change this text.</p>
8
9<button type="button" onclick="loadDoc()">Change Content</button>
10
11<script>
12function loadDoc() {
13 var xhttp = new XMLHttpRequest();
14 xhttp.open("GET", "ajax_info.txt", false);
15 xhttp.send();
16 document.getElementById("demo").innerHTML = xhttp.responseText;
17}
18</script>
19
20</body>
21</html>
22