[英]Getting Undefined Error when trying to store ajax JSON response into variable
I am trying to make ajax call and i want to store the JSON
response into variable. 我正在尝试进行ajax调用,我想将
JSON
响应存储到变量中。
Because the JSON response, i want to pass it to two Jqgrids
. 因为是JSON响应,所以我想将其传递给两个
Jqgrids
。 One will display half of the response and another will display remaining response. 一个将显示一半的响应,另一个将显示剩余的响应。 Please help me with some idea to display on
Jqgrids
. 请帮我一些想法在
Jqgrids
上显示。
This is how i am trying to store JSON
response, but i am getting undefined error
while passing variable to alert()
function. 这就是我试图存储
JSON
响应的方式,但是在将变量传递给alert()
函数时遇到了undefined error
。
var form_data;
$(searchBTN).click(function(event))
{
$.getJSON("search?dealId=" + orderId,
function(json) {
form_data = json.CompanyName;
checkdata();
});
function checkData() {
console.log(form_data);
alert(form_data);
}
}
请检查您的json数据格式,意味着json数组变量键。我认为您访问了错误的变量。未定义错误表明您当前的键在json对象中未定义。要进行测试,请使用此alert(JSON.parse(json))
A better way to do what I think you intend is as follows: 进行我认为您打算的更好的方法如下:
var form_data;
$(searchBTN).click(function(event)) {
$.getJSON("search?dealId=" + orderId, function(json){
form_data = json.CompanyName;
console.log(form_data);
alert(form_data);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.