[未解决] 怪异的 ajax

在编写一个读取 address 信息的 ajax,回来一个空值,可是这个 function 拿出来单独使用,又是正常的,代码如下:

$("#formRequest #item_id").load(function() {
    var uid = $("#item_" + $(this).val()).val();
    getReceiver(uid, "#item_ship_receiver");
    getAddress(uid, "#item_ship_address");
    getPhone(uid, "#item_ship_phone");
    getEmail(uid, "#item_ship_email");
});

$("#formRequest #item_id").change(function() {
    var uid = $("#item_" + $(this).val()).val();
    getReceiver(uid, "#item_ship_receiver");
    getAddress(uid, "#item_ship_address");
    getPhone(uid, "#item_ship_phone");
    getEmail(uid, "#item_ship_email");
});

function getReceiver(uid, jqTarget) {
    $.getJSON(
        "http://www.tenso-japan.com/tenso/api.php/discuz/getMember/" + uid,
        function(data) {
            $(jqTarget).val(data.realname);
        }
    );
}

function getAddress(uid, jqTarget) {
var address = '';
console.log(uid);
$.ajax({
        url: "http://www.tenso-japan.com/tenso/api.php/discuz/getMember/" + uid,
        dataType: 'json',
        async: false,
        success: function(data) {
            address = data.address;
            console.log(data);
        }
    });
    console.log(address);
    /*
    $.getJSON(
        "http://www.tenso-japan.com/tenso/api.php/discuz/getMember/" + uid,
        function(data) {
            $(jqTarget).val(data.address);
        }
    );*/
}

function getPhone(uid, jqTarget) {
    $.getJSON(
        "http://www.tenso-japan.com/tenso/api.php/discuz/getMember/" + uid,
        function(data) {
            $(jqTarget).val(data.mobile);
        }
    );
}

function getEmail(uid, jqTarget) {
    $.getJSON(
        "http://www.tenso-japan.com/tenso/api.php/discuz/getMember/" + uid,
        function(data) {
            $(jqTarget).val(data.email);
        }
    );
}

待研究…

你可能感兴趣的:(未解决)