简体   繁体   中英

Cross domain request with JSON response

I am trying cross domain request from my js file.

First,I was trying JSONP but my target domain URL is not support it. It return plain JSON object.

I am authorize person to access my target domain URL. but i can not modify it as per JSONP response.

SO how can i get JSON response from my target domain URL?

I have always done it with jsonp, by passing a callback b/c services return json, if call back is passed then it will wrap all json in callback else they will simple return json.

But in your case

You can look up with this article http://www.webdevdoor.com/jquery/cross-domain-browser-json-ajax/

Without modifying a bit the server side there is not much you can do. The general policy is to not to allow cross domain requests.

There are few things worth mentioning though:

  1. Try changing the server side so it will support JSONP.
  2. If the HTTP response contains Access-Control-Allow-Origin header then you can communicate with it with normal AJAX. This feature is supported in modern browsers only. Check this out for more info.
  3. You can do the cross domain requests with Flash and/or WebSockets. However server does have to support them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM