0

I want to create a cordova generic client for debug purpose. but I face the cross domain request problem. My case is: 1. I deploy my source code (html code) on a web server A. 2. My backend data source is from server B. 3. I create a cordova app and run on the device or simulator. the App access the url from server A and open the app page, that work fine. but when my js code read data from Server B, all request is failed. I guess it's cause by cross domain restriction.

Any one have solution to resolve this problem?

Thanks!

1 Answers1

0

Well, since your initial HTTP request goes through and HTML is returned, it seems that the connection from the Cordova is working, at least for server A.

What you could try is to upload temporarily "content" to server A which you try to fetch with AJAX calls.

If that succeeds, you can be sure that the fault is on server B and CORS works okay from front-end. In which case you could try to access the A & B from web client etc. to see possible differences in response headers. The server B is in that case probably missing Access-Control-Allow-Origin: * header. Try to add it to your server configuration or try JSONP. Also as a long shot, read your config.xml if you have only allowed connections to server A with

<access origin="<server A>"/>

in which case you obviously need to allow server B too.

If that fails, there is much less to work with and I can only suggest you to study resources like enable-cors.org which demonstrate how to actually allow CORS.

Community
  • 1
  • 1
Roope Hakulinen
  • 7,326
  • 4
  • 43
  • 66