Hello all!
So here is my current predicament: I need to run some javascript within a page that, every 30 seconds, posts a JSON object back to a PHP web service that resides on a different domain. Once this data makes it to the cross-domain, it is taken by the PHP web service and pushed into a database hosted there. The idea is to have this open source so that anybody that wants to incorporate this application on their own site has to download a minimal amount of files. Here is how my current understanding of how this could be accomplished works (please note that when I refer to "locally hosted" I am referring to the server that the relevant application resides on, not the client):
1. Have a JSON object on the page where somebody wanted this application to run.
2. Every 30 seconds, use an AJAX post to send this JSON object to a locally hosted .php file.
3. Have the locally hosted .php file format the JSONP object accordingly and send it to the cross-domain .php web service.
4. Have the web service push the data into a locally (on the cross-domain) hosted MySQL database.
5. Have the web service return a JSONP object that signifies the push was successful.
6. Have the locally hosted .php file return the successful flag to the page.
7. Have some javascript implementation on the page itself that shows that the upload went according to plan.
All that being said, here are the questions I have about this process:
First and foremost, is this even the best approach? I have heard JSON is more efficient to pass back and forth than xml.
Second, assuming that this is a proper approach, can somebody point me to some reference material as to how to send JSONP data across domains via php?
Third, if there are any glaring security flaws with this approach, what are they and how do I overcome them? The domain that the MySQL database and php web service will reside on is static, so hard-coding where to send requests to and accept responses from would not be a problem.
Any advice whatsoever on how to approach this process would be greatly appreciated. Thank you in advance!