0

I am developing a hybrid app using phonegap. All my html,css,js files reside in the mobile phone itself. Now, How can I make a call to a server to send/receive data from mobile? Using Ajax if I test locally on my desktop, I get this error!

"XMLHttpRequest cannot load http://domain1.com/test/login.php. Origin
 http://localhost is not allowed by Access-Control-Allow-Origin. "
  1. So will I be getting same-origin issues while trying to access the server even after deploying on to the mobile?
  2. Should I use JSONP for this? but again I cant send huge data in GET and POST doesn't work with JSONP!
  3. Host all my files on the server itself and call each page as and when required from the webview?
  4. Allow access from any origin in my server? For testing I can do this but for deployment on client location I don't think its a good idea!
  5. Any other approaches please?

Please help me as I am so new to this world!!

1 Answers1

1

you need to set header..

header("Access-Control-Allow-Origin: *"); 

and at the application end please set.

<access origin="*"/>

please check link for more details.

XMLHttpRequest cannot load.?

Community
  • 1
  • 1
JDev
  • 2,485
  • 1
  • 16
  • 21