如何通过一个值到PHP阿贾克斯变量
问题描述:
这是我的javascript code:
this is my javascript code :
function category(row){
dataparam = "oper=delete&row="+row;
$.ajax({
type: "POST",
url: "multiupload.php",
data: dataparam,
error:function() {
alert("sorry")
},
success: function(html) {
alert(html);
}
});
}
和我的PHP脚本:
$opers = (isset($_REQUEST['opers']) and $_REQUEST['opers'] != '' ) ? $_REQUEST['opers'] : '';
if($opers == "delete") {
$row=$_REQUEST['row'];
echo $row;
}
这是不工作...我不知道是什么问题。请帮我拿到了 $行
变量在我的PHP脚本。
This is not working... I don't know what problem is. Please help me to get the $row
variable in my php script.
答
它看起来像你有这个毛病, $ _ REQUEST ['OPERS']
应该是 $ $ _ REQUEST ['OPER']
It looks like you have this wrong, $_REQUEST['opers']
it should be $_REQUEST['oper']
$opers = (isset($_REQUEST['oper']) and $_REQUEST['oper'] != '' ) ? $_REQUEST['oper'] : '';
if($opers == "delete") {
$row=$_REQUEST['row'];
echo $row;
}
我也建议,当你期待的值来通过URL使用适当的超级全球是 $ _ GET
。有一个很小的机会,一个 $ _ COOKIE
可以拧你了。如果你使用它们,hapen给它OPER'的值。
I would also recommend that as you are expecting the values to come via URL you use the appropriate super global which is $_GET
. There is a very small chance that a $_COOKIE
could screw you over. If you use them and hapen to give it the value of 'oper'.