jQuery Phonegap Cordova Ajax 请求 404(未找到)错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30048453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Phonegap Cordova Ajax requests 404 (Not Found) Error
提问by Sahil
My cordova version is 5.0.0
我的科尔多瓦版本是5.0.0
I am getting a 404 error for the all ajax request made when the app is deployed on the device. On the web browser, it works fine but same app when deployed on a device does not work.
当应用程序部署在设备上时,我收到所有 ajax 请求的 404 错误。在网络浏览器上,它工作正常,但部署在设备上的同一个应用程序不起作用。
I tried adding following to solve the issue but it hasn't helped.
我尝试添加以下内容来解决问题,但没有帮助。
Config.xml
配置文件
<access origin="*" />
AndriodManiest.xml
AndriodManiest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I also added following in my index.html file but it didn't make any difference either.
我还在我的 index.html 文件中添加了以下内容,但它也没有任何区别。
<script>
$.support.cors=true;
</script>
Anyone here has another trick to solve this issue?, Seems to be a quite common issue with phonegap but the fixes above worked in older vesion of the phonegap/cordova but non of them has worked in my case.
这里有人有解决这个问题的另一个技巧吗?,这似乎是 phonegap 的一个很常见的问题,但上述修复程序在较旧的 phonegap/cordova 版本中有效,但在我的情况下没有一个有效。
Any help would be great.
任何帮助都会很棒。
回答by Derek Arends
I had the same issue and had to install the cordova-plugin-whitelist
我有同样的问题,不得不安装cordova-plugin-whitelist
cordova plugin add cordova-plugin-whitelist
Credit goes to this stackoverflow article - Ajax Command to request URL no longer working
归功于此 stackoverflow 文章 -请求 URL 的 Ajax 命令不再有效
回答by Damien
It should actually add the cordova whitelist plugin :
它实际上应该添加cordova白名单插件:
cordova plugin add cordova-plugin-whitelist
or in your config.xml file :
或在您的 config.xml 文件中:
<plugin name="cordova-plugin-whitelist" spec="1" />
but if you are using the online phonegap build service the syntax is different. You have to add the following line in your config.xml file :
但如果您使用在线 phonegap 构建服务,则语法不同。您必须在 config.xml 文件中添加以下行:
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
and authorize cross domain requests :
并授权跨域请求:
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
This is not recommended because a wildcard is used everywhere and everything is permitted. But it is perfect for your tests.
不建议这样做,因为到处都使用通配符,并且一切都被允许。但它非常适合您的测试。
回答by SeanBarberPro
This worked for me. The only difference is in my config.xml I had to put it in an node for it to take effect.
这对我有用。唯一的区别是在我的 config.xml 中,我必须将它放在一个节点中才能生效。
My example below:
我的例子如下:
<platform name="android">
<allow-intent href="market:*" />
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
</platform>
回答by Bruno PIERRE-JUSTIN
Phonegap User. Adding this line into the config.xml is the solution for me:
Phonegap 用户。将此行添加到 config.xml 是我的解决方案:
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
回答by grandia
My problem was a bit different. I compiled the app using a CI pipeline. So, you still need to do all the above (install the whitelist and add internet permission)
我的问题有点不同。我使用 CI 管道编译了该应用程序。因此,您仍然需要执行以上所有操作(安装白名单并添加互联网权限)
and you also need to find a Visual Studio version that will build the app correctly. Mine doesn't give an error when building, but the resulting app can't make any ajax request
并且您还需要找到可以正确构建应用程序的 Visual Studio 版本。我的在构建时没有给出错误,但生成的应用程序无法发出任何 ajax 请求
After I downgraded to VS2017, it works
我降级到VS2017后,就可以了