当我使用ajax获取json结果时,我设置了用于存储响应的全局变量,但是当我使用console.log时,它也未定义,我不知道为什么,我使用PHP EOT编写ajax调用并声明javascript变量,这是我的代码,如下所示:
以及如何将json结果与var json和json2关联?
ajax.php
INFO - FTPS connect() done: 220 (vsFTPd 3.0.2)
INFO - FTPS prot_p() done: 200 PROT now Private.
INFO - FTPS login() done: 230 Login successful.
INFO - FTPS session successfully opened
-rw------- 1 ftp ftp 86735 Mar 22 16:55 MyModel.yaml
-rw------- 1 ftp ftp 9298 Mar 22 16:55 MyData.csv
226 Directory send OK.
INFO - FTPS close() done
INFO - FTPS session successfully closed
getQTY.php
$WH_GridLoadComplete = <<<WH_GridComplete
var json;
var json2;
$.ajax({
type:'POST',
url:'getQTY.php',
data:{"param3":"asdf"},
dataType:"json",
success:function(response){
var json_object = JSON.parse(response);
json = JSON.stringify(json_object);;
}
});
$.ajax({
type:'POST',
url : 'getQTY.php',
data : {"testing":"asdf"},
dataType: "json",
success : function(response){
var json_object = JSON.parse(response);
json2 = JSON.stringify(json_object);
}
});
console.log(json);
console.log(json2);
WH_GridComplete;