jQuery.post 方法与实例教程
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");
补充:网页制作,jquery