PhoneGap中的Web服务

时间:2013-04-25 11:35:40

标签: android web-services cordova undefined

我是phonegap的新手。我卡住了我在电话间隙中调用webservice时无法获得结果。我使用了Ajax和getJSON方法。获得未定义的结果,RealData变量为undefined。我觉得我错过了什么。请帮帮我们 这是我的代码......

function onDeviceReady() {

    console.log("Device is Ready111111");
    alert("alert Device ready");

    /*var jqxhr = $
                .getJSON(
                'http://www.infoline.in/mobdata.aspx?
                                          reqfor=area_list&city=ahmedabad',
                        function() {

                            console.log("Device is Ready111111....."+jqxhr);
                            alert('success');
                        }).error(function() {
                    alert('error');
                });*/
    $(document).ready(function () {
        $.ajax({

            url: "http://www.infoline.in/mobdata.aspx",
            data: {
                "reqfor": "area_list",
                "city": "ahmedabad"
            },
            crossDomain: true,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg, textStatus, jqXHR) {
                alert(textStatus);

                var theRealData = msg.d;
                alert(theRealData.length)
            }
        });
    });

1 个答案:

答案 0 :(得分:1)

要查看对象,您必须将msg转换为字符串。

试试这个:

console.log(JSON.stringify(msg));
相关问题