1 $.ajax({
2 url : 'more_com.php', //PHP file to execute
3 type : 'GET', //method used POST or GET
4 data : {variable1 : "some data"}, // Parameters passed to the PHP file
5 success : function(result){ // Has to be there !
6
7 },
8
9 error : function(result, statut, error){ // Handle errors
10
11 }
12
13 });
14
15// NOTE : Parameters will be available either through $_GET or $_POST according
16// to the method you choosed to use.
17// Here you will get your variable "variable1" this way : $_GET['variable1']
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 url: url,
3 dataType: "json",
4 type: "Post",
5 async: true,
6 data: { },
7 success: function (data) {
8
9 },
10 error: function (xhr, exception) {
11 var msg = "";
12 if (xhr.status === 0) {
13 msg = "Not connect.\n Verify Network." + xhr.responseText;
14 } else if (xhr.status == 404) {
15 msg = "Requested page not found. [404]" + xhr.responseText;
16 } else if (xhr.status == 500) {
17 msg = "Internal Server Error [500]." + xhr.responseText;
18 } else if (exception === "parsererror") {
19 msg = "Requested JSON parse failed.";
20 } else if (exception === "timeout") {
21 msg = "Time out error." + xhr.responseText;
22 } else if (exception === "abort") {
23 msg = "Ajax request aborted.";
24 } else {
25 msg = "Error:" + xhr.status + " " + xhr.responseText;
26 }
27
28 }
29 });
1$.ajax({
2 type:"GET/POST",
3 url: "target url",
4 data: "var1=" + data1,
5 success: function(msg){
6 $("#targethtml").html(msg)
7 },
8 error: function(errormsg){
9 console.log(errormsg)
10 }
11});
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 });