在phonegap /本地jquery或sencha上向远程服务器发出Ajax请求
Mobile Device(file://..) Server
index.html <--JSON--- post.php
main.js
sencha_.js or Jquery_.js
情况就像上面这样, 所有文件(js、html)均由 PhoneGap 存储在移动设备上。(file://.../www/index.html...) 它将通过WebView显示。
main.js 会调用 $.ajax() 或 Ext.Ajax.request() 从服务器接收 json 数据。 (无论 POST/GET)
有可能吗?是否存在跨域问题?
Mobile Device(file://..) Server
index.html <--JSON--- post.php
main.js
sencha_.js or Jquery_.js
The situation is like above,
All files (js,html) is on the mobile device by PhoneGap.(file://.../www/index.html...)
It will be showed by WebView.
and main.js will call $.ajax() or Ext.Ajax.request() to receive json data from server. (whatever POST/GET)
is it possible? is there cross-domain problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这很有可能。由于您的 PhoneGap 应用程序是从 file:// 协议运行的,因此同源策略不适用,即不存在跨域问题。
Yes, it is very possible. Since your PhoneGap application is running from the file:// protocol the same origin policy does not apply, that is, no cross domain issues.
Phonegap 允许向任何服务器发出请求,您不需要使用任何 hacky 解决方案,它就可以工作,只要您在 AndroidManifest.xml 中有以下行
Phonegap allows to do requests to any server, you don't need to use any hacky solutions, it just works, as long as you have the following line in AndroidManifest.xml
是的,您可以,但不能使用本机 AJAX 方法。
建立跨浏览器连接的方法之一是创建一个
script
标记并通过回调方法解析所有参数:仅 GET
http:// myPage.com/service.php
$_GET["callback"]
是MY_CALLBACK
,它是我们在全局范围内的 javascript 方法。希望你能明白。
如果您使用的是框架,我认为几乎所有框架都有一种方法可以做到这一点。
jQuery
但你没有错误处理程序:(
你使用插件 jQuery。 jsonp 获取错误处理程序:来自:http://code.google.com/p/jquery-jsonp/wiki/TipsAndTricks
Yes you can but not using native AJAX methods.
One of the ways to make cross browser connections is to make a
script
tag and parsing all parameters to it via with a callback method:GET only
http://myPage.com/service.php
$_GET["callback"]
isMY_CALLBACK
witch is our javascript method in the global scope.Hope you can get the idea.
If you are using a framework i think almost all of then have a method to do this.
jQuery
but you have no error handler :(
You use the plugin jQuery.jsonp to get an error handler: From: http://code.google.com/p/jquery-jsonp/wiki/TipsAndTricks