Rickyrock
Rickyrock

Reputation: 328

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?

Upvotes: 0

Views: 31862

Answers (3)

developerCK
developerCK

Reputation: 4506

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/

Upvotes: 1

Shibbir Ahmed
Shibbir Ahmed

Reputation: 1350

Don't know what type application you are developing. But in ASP.NET you can do it by using a proxy page

These links may be helpful:

http://www.codeproject.com/Articles/667611/ASP-NET-Proxy-Page-Used-for-Cross-Domain-Requests

http://encosia.com/use-asp-nets-httphandler-to-bridge-the-cross-domain-gap/

https://gist.github.com/jkresner/3982746

Upvotes: 0

freakish
freakish

Reputation: 56467

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.

Upvotes: 1

Related Questions