0

This question have been bothering me for a while. So here is the story. There is another domain name which consist of a php file that produce json result : lets say http://www.otherdomain.com/token.php and it will produce:

{"token":"123455"}

I want to ajax from mywebsite.com to get and act on the response given. The problem is otherdomain.com is not own my me and I can't modify the content in it or whatsoever.

So I have searched for several answer on stackoverflow and will explain why this doesn't work.

  1. set the CORS header. It didnt work because the domain is not own by me and i can't do anything about it.

  2. Use my server as a proxy to request the data. (This is workable for a few times, but when the visitor on my site get more and more there will be more data sent from single ip to the site which is from my server which then might triggered 403 error)

  3. Use plugin on chrome or firefox. (This option is okay if i am the only one who using this website)

  4. Use JsonP. It shown in jQuery getJSON works locally, but not cross domain but the answer shows you need to modify the response data on the otherdomain.com file and since i dont own the domain, I cant do anything.

Community
  • 1
  • 1
dramasea
  • 3,370
  • 16
  • 49
  • 77
  • 1
    Seems like you've covered all the bases and eliminated each possibility. Not sure what else there is to say. It's their data, and if they don't want to make it easily accessible to other sites, they're not required to. –  Apr 05 '17 at 11:44
  • 2
    Ask the otherdomain to allow cross-origin resource sharing with your domain. Anything else is just shady practices. – apokryfos Apr 05 '17 at 11:44
  • If JSONP doesn't work, you're out of luck. – Tom Apr 05 '17 at 11:45
  • Solution seems to be here http://stackoverflow.com/questions/14149729/get-json-data-from-url-using-ajax-if-possible – Artem Ankudovich Apr 05 '17 at 11:57
  • lol, so no luck for me? – dramasea Apr 05 '17 at 11:57
  • @ArtemAnkudovich no it didnt work as the format of the response is json not jsonp – dramasea Apr 05 '17 at 12:06

1 Answers1

0

You may not use your option number 4 correctly. jsonp is especially made for cross domain requests. So, jsonp is your solution. If you stuck, then look at google maps or other services, they have working jsonp examples.

alpham8
  • 1,314
  • 2
  • 14
  • 32