jQuery.post 方法與執行個體教程

來源:互聯網
上載者:User

jquery.post( url, [ data ], [ success(data, textstatus, xmlhttprequest) ], [ datatype ] )

returns: xmlhttprequest


jquery.post( url, [ data ], [ success(data, textstatus, xmlhttprequest) ], [ datatype ] )
烏拉字串,其中包含的url的請求被發送。

dataa地圖或字串,發送到伺服器的請求。
success(data, textstatus, xmlhttprequest)a callback function that is executed if the request succeeds.

datatypethe type of data expected from the server.

this is a shorthand ajax function, which is equivalent to:

$.ajax({
  type: 'post',
  url: url,
  data: data,
  success: success
  datatype: datatype
});


這一成功是通過回呼函數返回的資料,這將是一個xml根項目或文本字串根據響應的mime類型。它還通過了響應文本的地位。

在jquery 1.4,成功回呼函數也是通過xmlhttprequest對象。

大多數實現將指定一個成功的處理常式:

$.post('ajax/test.html', function(data) {
  $('.result').html(data);
});


examples:
例如:請test.php教程網頁,但忽略了返回結果。

$.post("test.php");

example:

request the test.php page and send some additional data along (while still ignoring the return results).
請求test.php網頁,發送一些額外的資料沿(同時仍忽略了返回結果)。
$.post("test.php", { name: "john", time: "2pm" } );

example: pass arrays of data to the server (while still ignoring the return results).
$.post("test.php", { 'choices[]': ["jon", "susan"] });

example: send form data using ajax requests
$.post("test.php", $("#testform").serialize());

example: alert out the results from requesting test.php (html or xml, depending on what was returned).
$.post("test.php", function(data){
   alert("data loaded: " + data);
 })

;example: alert out the results from requesting test.php with an additional payload of data (html or xml, depending on what was returned).
$.post("test.php", { name: "john", time: "2pm" },
   function(data){
     alert("data loaded: " + data);
   });example: gets the test.php page content, store it in a xmlhttpresponse object and applies the process() 網頁特效 function.
$.post("test.php", { name: "john", time: "2pm" },
   function(data){
     process(data);
   }, "xml");


example: gets the test.php page contents which has been returned in json format ()
$.post("test.php", { "func": "getnameandtime" },
   function(data){
     alert(data.name); // john
     console.log(data.time); //  2pm
   }, "json");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.