This is a mon issue for people to have but all of the solutions on StackOverflow seem to center around installing cordova-plugin-whitelist
, adding some variation on
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
to config.xml
, and adding something like
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' *">
to your index.html
file. I've tried all of these things but still no luck. What's really frustrating is I had worked on a previous project where these things did work as a solution but using the same configuration on the new project just doesn't work.
I'm 100% sure that the requested URL is responding properly. Even when I click on the URL from the 404 error in the Chrome Dev Inspector it returns the proper content. Is there anything to try not mentioned in the same answers that you see over and over when you search for this question?
Edit:
In response to the first ment, this is the javascript code:
var xhr = new XMLHttpRequest();
xhr.open("POST", "");
xhr.onload = success_callback;
xhr.onerror = error_callback;
xhr.send(content);
This exact same code works fine when I load it in a desktop browser, the 404 only occurs in the cordova app. There's no difference in the code, it's just me running cordova build browser
vs me running cordova build android
.
This is a mon issue for people to have but all of the solutions on StackOverflow seem to center around installing cordova-plugin-whitelist
, adding some variation on
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
to config.xml
, and adding something like
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' *">
to your index.html
file. I've tried all of these things but still no luck. What's really frustrating is I had worked on a previous project where these things did work as a solution but using the same configuration on the new project just doesn't work.
I'm 100% sure that the requested URL is responding properly. Even when I click on the URL from the 404 error in the Chrome Dev Inspector it returns the proper content. Is there anything to try not mentioned in the same answers that you see over and over when you search for this question?
Edit:
In response to the first ment, this is the javascript code:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://example./endpoint");
xhr.onload = success_callback;
xhr.onerror = error_callback;
xhr.send(content);
This exact same code works fine when I load it in a desktop browser, the 404 only occurs in the cordova app. There's no difference in the code, it's just me running cordova build browser
vs me running cordova build android
.
- What's your code look like? What's the URL? Can the Android device / simulator etc resolve that URL? Do you get anything of interest in the JS console in the Chrome remote inspector? – Simon Prickett Commented Dec 4, 2015 at 2:27
- The code is a pretty standard usage of XMLHtppRequest, I'm fairly experienced in using it and I really don't think that it's where the issue lies. Additionally, the code works fine when I just load it in the browser instead of running it within an app.I get the same behavior on the emulator that I do on real devices. The 404 error es up in the Chrome remote inspector when the request is made and includes the link that returned 404 as a link in the inspector. When I click on the link it works as expected in the browser. – Ivanna Commented Dec 4, 2015 at 2:53
- One time this happened with me. Removed and reinstalled the plugin and it suddenly worked. Don't know if it might help in your case tho. – user1027620 Commented Dec 4, 2015 at 3:02
- Thanks, this worked! No clue why I needed to do that this time but I'm extremely grateful for a solution. – Ivanna Commented Dec 4, 2015 at 3:54
- @user1027620, if you post that as an answer then I'll be happy to accept it because it was the right thing to do in this case. – Ivanna Commented Dec 4, 2015 at 5:34
1 Answer
Reset to default 12One time this happened with me.
List all installed plugins:
cordova plugin list
All I had to do was remove the plugin:
cordova plugin remove <PLUGIN_NAME>
(cordova-plugin-whitelist in that case)
Then add it again:
cordova plugin add cordova-plugin-whitelist