Thứ Năm, 30 tháng 8, 2012

Truyền biến theo phương thức POST sử dụng jquery-ajax

Cú pháp:
$(selector).post(url,data,success(response,status,xhr),dataType);

ParameterDescription
urlRequired. Specifies the url to send the request to
dataOptional. Specifies data to send to the server along with the request
success(response,status,xhr)Optional. Specifies the function to run if the request succeeds
Additional parameters:
  • response - contains the result data from the request
  • status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr - contains the XMLHttpRequest object
dataTypeOptional. Specifies the data type expected of the server response.
By default jQuery performs an automatic guess.
Possible types:
  • "xml" - An XML document
  • "html" - HTML as plain text
  • "text" - A plain text string
  • "script" - Runs the response as JavaScript, and returns it as plain text
  • "json" - Runs the response as JSON, and returns a JavaScript object
  • "jsonp" - Loads in a JSON block using JSONP. Will add an "?callback=?" to the URL to specify the callback


Example:
$.post('1.php',{bien1:"value1"},function(result){
     $('#container').html(result);
});

0 nhận xét:

Đăng nhận xét

 
Copyright © hoangit