jQueryMobile,PhoneGap getJSON方法没有执行

时间:2011-11-30 21:03:10

标签: jquery-mobile cordova

我正在运行一个在PhoneGap中运行的示例jQueryMobile应用程序。问题是它没有运行getJSON回调来检索数据,如下所示:

$( function() 

    {       
        $('#searchButton').click(function() 
        {

            alert("search clicked"); <== this alert works  

            var url = "http://api.alternativeto.net/software/firefox?callback=?";

            $.getJSON(url, function(data) <== this should be, but isn't being called
            {
                alert("function data called");  <== so this alert doesn't show.      

             } // end function (data) 

            ); // end getJSON

            alert("getJSON call completed");    <== and this alert works
        } //  end search click.function()
    ); // end $(

“click clicked”和“getJSON call completed”警报都有效。我在浏览器中输入url时返回的JSON是有效的。

测试代码来自以下网址:

http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile

还有什么我可以检查的吗?

1 个答案:

答案 0 :(得分:0)

我认为您不需要?callback=?中的url,因为您可以从应用发出跨域请求。

我取得了成功:

$.getJSON('http://google.com/', function (data) {console.log(data);});

..记录了Google主页的HTML。

相关问题