1$.ajax({
2 type: "post", url: "/SomeController/SomeAction",
3 success: function (data, text) {
4 //...
5 },
6 error: function (request, status, error) {
7 alert(request.responseText);
8 }
9});
10
1$.ajax({
2 url: 'some_unknown_page.html',
3 success: function (response) {
4 $('#post').html(response.responseText);
5 },
6 error: function (jqXHR, exception) {
7 var msg = '';
8 if (jqXHR.status === 0) {
9 msg = 'Not connect.\n Verify Network.';
10 } else if (jqXHR.status == 404) {
11 msg = 'Requested page not found. [404]';
12 } else if (jqXHR.status == 500) {
13 msg = 'Internal Server Error [500].';
14 } else if (exception === 'parsererror') {
15 msg = 'Requested JSON parse failed.';
16 } else if (exception === 'timeout') {
17 msg = 'Time out error.';
18 } else if (exception === 'abort') {
19 msg = 'Ajax request aborted.';
20 } else {
21 msg = 'Uncaught Error.\n' + jqXHR.responseText;
22 }
23 $('#post').html(msg);
24 },
25});
26
1 $.ajax({
2
3 url : "file.php",
4 method : "POST",
5
6 data: {
7 //key : value
8 action : action ,
9 key_1 : value_key_1,
10 key_2 : value_key_2
11 }
12 })
13
14 .fail(function() { return false; })
15 // Appel OK
16 .done(function(data) {
17
18 console.log(data);
19
20 });