iPhone &音位间隙
我尝试从 iphone 应用程序连接到一个简单的 json web 服务 - 用 Phonegap 制作(所以直接从 iPhone 模拟器),但我无法做到这一点。
Web 服务器很简单,接收 2 个参数并将相同的参数返回给应用程序 - 仅用于测试(位于另一台服务器)。 客户:
//here we make the call to the webservice
var TheURL = "http://www.wsurl.com/json_ws/json_webserver.php?";
TheURL += 'latitude=' + latitude + '&';
TheURL += 'longitude=' + longitude + '&';
TheURL += 'jsoncallback=?';
if(checkConnection()){
$.getJSON(TheURL,function(msg){alert(msg); });
}
你有什么想法应该是错误的吗?
谢谢你!
I try to connect to a simple json webservice from an iphone application - made in phonegap(so directly from the iPhone simulator) but I can't manage to do it.
Webserver is simple, receive 2 params and return same params to application - just for testing(located to another server).
Client:
//here we make the call to the webservice
var TheURL = "http://www.wsurl.com/json_ws/json_webserver.php?";
TheURL += 'latitude=' + latitude + '&';
TheURL += 'longitude=' + longitude + '&';
TheURL += 'jsoncallback=?';
if(checkConnection()){
$.getJSON(TheURL,function(msg){alert(msg); });
}
Do you have any ideea about what should be wrong?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会检查并确保您的 Web 服务器的 url(以及任何其他外部加载的资源等)已通过将其添加到 PhoneGap.plist 文件中的ExternalHosts 键来添加到 PhoneGap 白名单中。
请参阅此处有关外部主机的常见问题解答:http://wiki.phonegap .com/w/page/41631150/PhoneGap%20for%20iOS%20常见问题解答
I would check and make sure your web server's url (and any other externally loaded assets, etc) have been added to the PhoneGap WhiteList by adding it to the ExternalHosts key in the PhoneGap.plist file.
See the FAQ about external hosts here: http://wiki.phonegap.com/w/page/41631150/PhoneGap%20for%20iOS%20FAQ
我要检查的两件事是:1)您正在使用 jQuery,您确定它已包含在项目中吗? 2) 在 TheURL += 'jsoncallback=?'; 之后放置 NSLog。然后在 safari 中复制并粘贴串联的 url,看看是否有效。我的猜测是“jsoncallback=?”中的问号是什么导致了问题,因为你在那里没有价值(如果在网址中发送,则需要对问号进行编码。我的猜测是你只是缺少应该占据该问号位置的值)
Two things I would check is: 1) You are using jQuery, are you sure it has been included in the project?. 2) Put a NSLog after TheURL += 'jsoncallback=?';. Then copy and paste the concatenated url in safari to see if it works. My guess is the question mark in "jsoncallback=?' is what's causing the problem seeing as how you have no value there (question mark needs to be encoded if sent in a url. My guess is you are just missing the value that is supposed to take that question marks spot)