Mobile apps - Cross-domain AJAX [duplicate]

强颜欢笑 提交于 2019-12-24 14:15:56

问题


I am trying to design some software to be distributed on private mobile devices (Android, iOS etc).

I would like to write the software with HTML/CSS/JavaScript and use something like Sencha Touch, PhoneGap or similar.

The software needs to write to a local database on the device and when it gets connectivity, post the data (securely) to a remote database on a web server.

I believe my problem will be posting the data to the server. As far as I can tell AJAX can use JSONP to request data cross-domain, but not to send data (at least not with POST method).

Can this be done using JavaScript? Perhaps Sencha Touch, PhoneGap or other mobile-app-compiling solutions have native storage and cross-domain posting methods?


回答1:


JSONP technically is a hack. CORS is the correct way to implement cross domain calls if you have control over your web service. This is a great post explaining how to enable CORS support in Web API. if you use some other technology for developing your web service, you can get tons of information from internet on how to CORS enable it .



来源:https://stackoverflow.com/questions/15363005/mobile-apps-cross-domain-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!