1$.ajax({
2 url:'your url',
3 type: 'POST', // http method
4 data: { myData: 'This is my data.' }, // data to submit
5 success: function (data, status, xhr) { // after success your get data
6 $('p').append('status: ' + status + ', data: ' + data);
7 },
8 error: function (jqXhr, textStatus, errorMessage) { // if any error come then
9 $('p').append('Error' + errorMessage);
10 }
11});
1 $.ajax({
2 url: "Url",
3 dataType: "json",
4 type: "Post",
5 async: true,
6 data: {"Key":value,"Key2":value2},
7 success: function (data) {
8
9 },
10 error: function (xhr, exception, thrownError) {
11 var msg = "";
12 if (xhr.status === 0) {
13 msg = "Not connect.\n Verify Network.";
14 } else if (xhr.status == 404) {
15 msg = "Requested page not found. [404]";
16 } else if (xhr.status == 500) {
17 msg = "Internal Server Error [500].";
18 } else if (exception === "parsererror") {
19 msg = "Requested JSON parse failed.";
20 } else if (exception === "timeout") {
21 msg = "Time out error.";
22 } else if (exception === "abort") {
23 msg = "Ajax request aborted.";
24 } else {
25 msg = "Error:" + xhr.status + " " + xhr.responseText;
26 }
27 if (callbackError) {
28 callbackError(msg);
29 }
30
31 }
32 });
1$.ajax({
2
3 // The URL for the request
4 url: "post.php",
5
6 // The data to send (will be converted to a query string)
7 data: {
8 id: 123
9 },
10
11 // Whether this is a POST or GET request
12 type: "GET",
13
14 // The type of data we expect back
15 dataType : "json",
16})
17 // Code to run if the request succeeds (is done);
18 // The response is passed to the function
19 .done(function( json ) {
20 $( "<h1>" ).text( json.title ).appendTo( "body" );
21 $( "<div class=\"content\">").html( json.html ).appendTo( "body" );
22 })
23 // Code to run if the request fails; the raw request and
24 // status codes are passed to the function
25 .fail(function( xhr, status, errorThrown ) {
26 alert( "Sorry, there was a problem!" );
27 console.log( "Error: " + errorThrown );
28 console.log( "Status: " + status );
29 console.dir( xhr );
30 })
31 // Code to run regardless of success or failure;
32 .always(function( xhr, status ) {
33 alert( "The request is complete!" );
34 });