Cordova 2.4 for windows phone 8 app not allowing cross domain requests with ajax request with jquery. This Cordova blocks the request and request will be ignored.
This scenario can happen in three scenarios.
- Loading external server URL
- Redirecting to another server
- Ajax Request
Basically you make this work by changing by white listing the right domains as below in config.xml
<access origin="http://yourdomain.com" />
This is implemented in Cordova for security of app to avoid the cross domain requests.
But what if, when we are not sure about the direct final URL or if it’s a dynamically changeable URL.
They should provide an option in such way that developer can bypass the checking for all domains. Something like
<access origin="*" /> // this is NOT A VALID Code
I checked the code and found that we can edit Cordova to make such an update.
Solution1: Quickest Solution
Remove config.xml. Trust me it will work, but this not the right solution
Solution2: Quicker Solution
You can either bypass by modifying lib / windows-phone-8 / wp8/ template/cordovalib /
CordovaView.xaml.cs as below
// Line 419
// Ref: https://github.com/phonegap/phonegap/blob/master/lib/windows-phone-8/wp8/template/cordovalib/CordovaView.xaml.cs
void CordovaBrowser_Navigating(object sender, NavigatingEventArgs e)
/* if (!configHandler.URLIsAllowed(e.Uri.ToString()))
Debug.WriteLine("Whitelist exception: Stopping browser from navigating to :: " + e.Uri.ToString());
e.Cancel = true;
this.PageDidChange = true;
Note: Jquery 2.x+ is not supporting cross domain request with following code
So degrade to jquery 1.9x and try any of above codes. This will make sure that $.ajax will work with native webview
jQuery.support.cors = true;