0

我想要一个 jQuery 脚本来接收一个 php 脚本的返回,该脚本$.post("script.php", args)在请求启动时发出数据库请求,但是如何处理任何答案?

4

3 回答 3

3

在开始学习之前,你真的应该阅读这些教程

回答你的问题

jQuery post 采用如下参数

jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )

具有某些参数的典型 jquery 发布请求,期望来自 XML 格式的 php 文件(在本例中为 test.php)的结果如下所示

$.post("test.php",
 { name: "John", time: "2pm" },
 function(data) {
   process(data);
 }, 
 "xml"
);

希望这可以帮助。

于 2012-04-16T16:35:20.030 回答
1
$.post("script.php", args, function(res) {
  // res is the response send to your from server
  // now do your stuff
});

阅读有关ajaxpost方法的信息,希望您能找到解决方案

于 2012-04-16T16:35:34.790 回答
1

正如许多人建议使用 jQuery 手册检查 POST 或 AJAX 调用的可能用法一样,这是我的 ajax 调用示例:

$.post("server.php", { "func": "getNameAndTime" }, function(data){
  console.log(data.name); //  John Doe
  console.log(data.time); //  2001-01-01 23:00:00
}, "json");

服务器.php

//do some processing and validation
$response = array('name' => 'John Doe', 'time'=> '2001-01-01 23:00:00');
print json_encode($response);
exit;
于 2012-04-16T16:56:03.390 回答