Jquery mobile json from php

Jquery mobile json from php

本文关键字:php from json mobile Jquery      更新时间:2023-09-26

am以json 的形式从php获取数据

代码:

I have added json_encode() to the php database output

JQUERY MOBILE:

$.getJSON('custom/php/showresults.php',
 function(data){
console.log(data)
}

console.log(数据)输出为:

{'name':'Geowan', 'surname':'hiu'}.

如何将其更改为以对象方式输出,以便使用data.name

您想直接访问数据吗?

$.getJSON('custom/php/showresults.php',
 function(data){
 console.log(data.name)
}

如果您希望它将其分配给变量

var jsonData = $.getJSON('custom/php/showresults.php',
 function(data){
 return data;
}
if(jsonData){
console.log(jsonData.whatever)
}

或简称

$.getJSON('custom/php/showresults.php',function(data){
    return data.whatever;
}