我和json这样的ajax调用从php代码中获取数据然后在我的页面中显示:
function get_customerdata(custID){
var serviceURL_customer = serviceURL + 'getcustomer.php';
$.ajax({
type: "GET",
url: serviceURL_customer,
async: false,
data: {id : custID},
dataType: 'json',
success: onSucess_displaycust
});
return false;
}
// --------------------------------------------------
function onSucess_displaycust(data)
{
var customer = data.item;
$('#custname1').text(customer.Name1);
... // other code
// --------------------------------------------------
// PHP code
$customer = $stmt->fetchObject();
...
$clean = utf8_string_array_encode($customer);
echo '{"item":' . json_encode($clean) .'}';
...
我想把变量
customer.Name1
这是我的json数据的提取:
//------------------------------------------
//json data
1. item: {ID:10011, UserID:XXX, Passwort:XXX, Name1:Bike Sport, Name2:XXX,…}
1. Name1: "Bike Sport"
这是我的json数据的确切响应:
{"item":{"ID":"10011","UserID":"XXX","Passwort":"XXX","Name1":"Bike Sport", ...
答案 0 :(得分:0)
您是否查看过Firebug或Chrome开发工具中的JavaScript控制台,看看是否有错误?我的猜测是onSucess_displaycust函数在你调用它的范围内是未定义的。