【发布时间】:2011-11-30 21:03:10
【问题描述】:
我正在运行一个在 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 $(
“搜索已点击”和“getJSON 调用已完成”警报都有效。我在浏览器中输入 url 得到的返回 JSON 是有效的。
测试代码来自这个网址:
http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
还有什么我可以检查的吗?
【问题讨论】:
-
我认为您不需要
url中的?callback=?,因为您可以从应用程序发出跨域请求(我已经成功使用$.getJSON('http://google.com/', function (data) {console.log(data);}))。 -
谢谢 - 这帮助我查看日志而不是警报,在那里我发现存在某种白名单问题。我认为这已经解决了,所以如果你把它作为一个答案,我会接受它。
标签: jquery-mobile cordova