文章摘要: jquery ajax跨域 phonegap/cordova本身支持跨域操作,关键点为: res\xml\config.xml中的 access 节点 *为不加任何限制,例如只允许读本机可以加入127.0.0.1 access origin = * / PS:html 文件只能在本机,不能在远端。 如图 $.post方式 代码如图 $.ajax方式
时间:2014-06-19 13:57来源:未知 作者:admin 点击: 次
文章TAG: phonegap webservice ajax
phonegap/cordova本身支持跨域操作,关键点为:
res\xml\config.xml中的access节点
*为不加任何限制,例如只允许读本机可以加入127.0.0.1
<access origin="*"/>
PS:html文件只能在本机,不能在远端。
如图
$.post方式
代码如图
$.ajax方式调用webservice
以asp.net为例
服务端要支持ajax读取(默认不支持),webservice代码如图
App端ajax代码,其中/Login为asmx webservice方法名
$.ajax({
type: "post",
contentType: "application/json",
url: "http://192.168.0.131:81/AppBMPService.asmx/Login",
data: "{p_szUserID: '123',p_szPassword:'123456' }",
dataType: "json",
success: function(result) {
alert(result.d);
}
});
|