Fix for Cross domain issues in Windows Phone 8 Hybrid app with Cordova 2.4 and JQuery

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.

  1. Loading external server URL
  2. Redirecting to another server
  3. 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

 

 

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

 

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