未捕获的TypeError:无法读取未定义的属性“数字”

时间:2014-09-06 10:05:26

标签: jquery json

我在网页上有JQuery代码,它以JSON格式从php函数中提取数据。只有在我单击按钮两次后才能执行代码。在chrome dev工具中,我看到第一个按钮的错误: 未捕获的TypeError:无法读取属性' number'未定义的

// JSON Data example:
{
    "number": "555",
    "street": "S La Veta Park Cir",
    "propertynumber": "",
    "city": "Orange",
    "state": "CA",
    "zip": "92868"
}

// Script

var address;
var propertyinfo;
$('.step1').siblings().hide(); // hide all except step 1

$('.search').click(function(){
    var filledaddress = $('#address').val();
    $.get("addresslibrary.php?command=parse&address="+filledaddress, function(addressdata){
        address = JSON.parse(addressdata);
    });
    $('#propertyTitle').html(address.number+' '+address.street+' '+address.propertynumber+'<br>'+address.city+' '+address.state+' '+address.zip);

    $(this).closest('.step').hide().next('.step').show();
    return false;
});
$('.back').click(function(){
    $(this).closest('.step').hide().prev('.step').show();
    return false;
});

1 个答案:

答案 0 :(得分:1)

在回调函数

中设置html
$.get("addresslibrary.php?command=parse&address="+filledaddress, function(addressdata) {
  address = JSON.parse(addressdata); 
  $('#propertyTitle').html(address.number+' '+address.street+' '+address.propertynumber+'<br>'+address.city+' '+address.state+' '+address.zip);
});