mautilus/sdk

how to make ajax request the cross domain using this sdk?

Closed this issue · 7 comments

Hello, I recently use your sdk to make a ajax request to other domain but failed all the time. I can't find a helpful way to resolve this problem, can you give any advice? thanks.

ok,I add a proxy server to solve this problem.

If you are using JSON, you might fail on XMLHttpRequest same domain policy. To overcome this problem, you need to add Cross-Origin Resource Sharing HTTP headers in server responses (by server itself, or via proxy). In PHP like:

And calling it: "http://your.domain/script.php?url=http://other.domain/url/resource.json"

Or you can use JSONP, where XMLHttpRequest same domain policy is tricked by jQuery by creating <script> elements, and parsing data from them. Disadvantages:

  • you need to have JSONP responses enveloped in callback function to pair requests with responses: someCallback({"key":"value"});
  • you have no control about the requests . I.e. you can't add headers to JSONP request, as it is made not by jQuery, but browser core (via <script> tag as describer above), or cancel request, etc.

Thank @SoCoxx ,
I have tried the JSONP, but It also need the server support the callback, if not, the client get failed response and get the info: parse error.

Are you getting this error on TV, or while testing in Chrome?

As @SoCoxx mentioned, the best way is to allow CORS on server responses. My question is on which platform you have such issue? Is your application hosed? When the application is installed and executed locally on LG and Samsung there is none problem with CORS.

@stenlik I run on samsung TV, and the server is run locally on tomcat server which developed by other memeber,so I can't change anythings in the server side.
same as this problem: http://stackoverflow.com/questions/23730216/jsonp-parse-error-with-jquery-ajax-request
Thanks.

If the application is installed and started locally from Samsung TV there is no CORS check, so you should not have any CORS related issues. CORS issues occurs only when the application is hosted.