你好,我是一个使用 jQuery 和 Ajax 的新手。我正在尝试使用 Jquery POST 方法将数据提交到服务器。我传递的数据是一个字符串。现在我无法理解如何传递数据以及如何检索数据。我尝试搜索有关我的问题的文章,但没有找到。我相信我的问题是非常基本的。
if (1)//validateStep(step)
{
if(step==1)
{
var data = document.getElementById('hiddenContact').value;
$.post('/callcenter/admin/postContacts', data);
}
}
现在我将发布 postContacts 操作的代码,这并不是什么大事。
function postContacts()
{
$this->autoRender = false;
echo '<script>console.log("post contacts");</script>';
}
但我对如何检索数据感到困惑。任何帮助表示赞赏。我使用 cakePHP,所以我不得不使用 autoRender=false;这使得视图可选。
With jQuery 帖子 http://api.jquery.com/jQuery.post/您可以定义一个回调函数,该函数在返回数据时执行:
$.post('/callcenter/admin/postContacts', data, function(returnedData) {
// do something here with the returnedData
console.log(returnedData);
});
The data
应采用以下形式:
{name: 'value', anotherName: 'another value'}
这相当于 PHP 端的帖子名称,可以用纯 PHP 访问,如下所示:
echo $_POST['name']; # prints "value"
echo $_POST['anotherName']; # print "another value"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)