jQuery - ajax get() and post() methods

get post is the method for client and server to request and respond.

    get -- is to request data from the specified resource.

    post--is to submit the data to be processed to the specified resource.

 

Some notes on get and post:

    get requests are cacheable post requests are not cached

    get requests stay in browser history post requests do not stay in browser history

    get requests can be bookmarked post cannot be bookmarked

    get requests should not be used when dealing with sensitive data post requests have no requirement for data length   

    get request has length limit

    get requests should only be used to retrieve data

    To put it simply, post can change the data style of the page with buttons and the like, but get cannot.

 

syntax format

$.get(URL,callback);   

$.post(URL,data,callback);  

The required URL parameter specifies the URL (request address) you wish to request.

The optional data parameter specifies the data to send with the request.

The optional callback parameter is the name of the function to execute after the request is successful.

 

example

GET()

$("button").click(function(){
  $.get("pos_test.asp",function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
  });
});

The first parameter of $.get() is the requested URL ("pos_test.asp").

The second parameter is the callback function. The first callback parameter holds the content of the requested page, and the second callback parameter holds the status of the request.

POST()

$("button").click(function(){
  $.post("pos_test_post.asp",
  {
    name:"liujun",
    city:"langfang"
  },
  function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
  });
});

  The first argument to $.post() is the URL we wish to request ("pos_test_post.asp").

Then we send the data along with the request (name and city).

The script in "pos_test_post.asp" processes them and returns the results.

The third parameter is the callback function. The first callback parameter holds the content of the requested page, and the second parameter holds the status of the request.

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326505395&siteId=291194637