jQuery的post方法
jQuery.post(url,[data],[callback],[type])
参数 | 描述 |
---|---|
url | 待载入页面的 URL 地址。 |
data | 待发送 Key / value 参数。 |
callback | 载入成功时回调函数。 |
type | 返回内容格式,xml, html, script, json, text, _default。 |
$.post("test.php", { "func": "getNameAndTime" }, function(data){ alert(data.name); // John console.log(data.time); // 2pm }, "json");
例子:
在html页面, 有form表单用了数组,可以:
$dataSource = $('form').serialize();
$.post("test.php", $dataSource,
function(data){
alert(data.name); // John
console.log(data.time); // 2pm
}, "json");
在test.php页面:
<?php
var_dump($_POST);
?>
就可以看到传递过来的元素了!
-------------我的签名档---------------------
年轻人,还需要多努力!
--------------------------------------------