Php 如何访问ajax post变量
如果我使用ajax这样发布:Php 如何访问ajax post变量,php,jquery,ajax,Php,Jquery,Ajax,如果我使用ajax这样发布: $('a.publish').live('click', function () { var id = $(this).attr('id').replace('item_', ''); var table= $(this).attr('rel'); $.ajax({ type: 'post', url: "", data: 'publish=' + id + '&table=' + ta
$('a.publish').live('click', function () {
var id = $(this).attr('id').replace('item_', '');
var table= $(this).attr('rel');
$.ajax({
type: 'post',
url: "",
data: 'publish=' + id + '&table=' + table,
success: function () {
$('#published_' + id).html(data);
count();
}
});
return false;
});
如何访问post变量表
?
我可以通过以下方式提取id
:
if (isset($_POST['publish'])) {
$id = intval($_POST['publish']);
Nemesis::update("projects", "published = '1'", "id = '{$id}'");
print "Active";
}
将返回表变量
如果不起作用,请在提交之前检查值是否正确。尝试console.log(table)
和/或检查firebug/chrome开发工具中的“网络”选项卡,查看您发送的是哪一份绘图
查看您提交给服务器的值。如果表为空,则错误在jquery中
服务器端调试可能会执行类似于
var\u dump($\u POST['table'])的操作。
也试试看
但现在我的问题是让echo工作 $('#published'+id).html(数据) 在函数中传递数据。像这样:
成功:函数(数据){
$('#published'+id).html(数据);
计数();
}
访问“publish”之类的变量,您可以编写
$table = $_POST['table'] die echo "var table is not available"
您可以通过$\u GET['']$\u POST[''']和$\u SERVER['''']
$\u POST['table']
访问环境变量,还是我缺少什么?(更新版本的jQuery不推荐使用.live
)从外观上看,您做得不错。你有没有检查过你的a
是否有rel
attr?是的,这是我第一次使用ajax,我读错了写的方式哈哈。我不知道我把$id归因于$u POST['publish'],这就是问题所在。谢谢;)但是现在我遇到的问题是如何让echo
使用$('#published_'+id).html(数据)代码>
$table = $_POST['table'] die echo "var table is not available"