This is a common 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 comment, this is the javascript code:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://example.com/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
.
One 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With