【发布时间】:2017-10-13 05:46:38
【问题描述】:
function submitID(){
// some codes working in here....
var text="A_1";
var name="test";
$.ajax({
url: 'callmethod.php',
type: 'post',
data: {'action':'methodname', 'text': text, 'name':name},
success: function(data, status) {
var results = JSON.parse(data);
for(var i = 0; i < results.length; i++){
var id= results[i]['ID'];
alert(id); --- I got the value of ID in here -- example output value : Hello
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
});
}
我想在这里做什么,我得到了 var id 的值,但我想设置为 PHP 变量 $valuephp= >>> id
【问题讨论】:
-
您不能将 JS 变量分配给 PHP 变量,因为这会带来安全风险。但是,您可以在
callmethod.php中设置 PHP 变量,如果您希望全局访问它,可以设置会话变量。