AJax技术

PhoneGapAJAX请求不工作 - PhoneGap AJAX request not working

字号+ 作者:H5之家 来源:H5之家 2015-11-03 10:05 我要评论( )

28im技术大牛是面向程序员的知识学习与分享社区,追求最前沿技术

PhoneGapAJAX请求不工作 - PhoneGap AJAX request not working

- 此内容更新于:2015-10-31

主题:

我使用PhoneGap最新版本,ajax调用。当我测试我的程序在桌面浏览器或移动PhoneGap开发应用,效果很好,但是在构建应用程序(.apk),ajax请求不工作和落在失败,而不是成功。我提到的所有配置包括:还Content-Security-Policy元标记在我的HTML和指出我的API所在域:我使用PhoneGap在线构建服务来构建应用程序。我真的需要帮助我做了所有我能找到的修复,但没有成功。

原文:

I am using latest PhoneGap version, and doing ajax calls.

$.ajax({ type : 'POST', url : 'http://example.com/path to my API', data : {d1: v1, d2: v2}, dataType : 'json', success : function(data) { console.log(data); }, error : function(){ alert('Error'); } });

When I test my app on desktop browser or mobile PhoneGap Developer App, it works fine, but after building application (.apk), ajax requests do not work and fall on failure rather than success. I have done all the configurations mentioned which include:

<access origin="*" /> <plugin version="1" /> <allow-navigation href="*" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" />

Also added Content-Security-Policy meta tags in my HTML and pointed to domain where my API is located:

<meta http-equiv="Content-Security-Policy" content="connect-src 'self' ">

I am using PhoneGap online build service to build app. I really need help as I have done all the fixes which I could find but no success yet.

解决方案:
@Nabeel,你很幸运。我现在完成了一篇博客文章在改变你的CSP跟进。它应该做的把戏,如果你正在与iOS9,你需要添加一些苹果。深入阅读文档的细节。最好的运气

原文:

@Nabeel, your are in luck. I am currently finishing up a blog post on whitelist

Change your CSP as follow. It should do the trick

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self' 'unsafe-inline' 'unsafe-eval';">

If you are working with iOS9, you'll need to add something for Apple's ATS. Read further on the document to get details on that.

Best of Luck

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 判断用户是不是为ajax请求

    判断用户是不是为ajax请求

    2016-02-24 17:00

  • 图解Ajax的工作原理

    图解Ajax的工作原理

    2016-01-18 09:00

  • 防止重复发送 Ajax 请求的解决方案

    防止重复发送 Ajax 请求的解决方案

    2016-01-18 08:20

  • jquery ajax同步请求

    jquery ajax同步请求

    2016-01-18 08:23

网友点评