Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

jquery - Making an ajax request from a different domain

This question has probably been answered before but I haven't been able to find a suitable answer.

I'm using asp.net web forms and am wanting to make a jquery Ajax request from one site on a particular domain to another site on another domain. The Ajax request is to a web method on an aspx page.

As expected I am having problems with CORS. My question is are you able to make an Ajax call to a web method on an aspx page from a different domain? If so any advice or links to resources would be very grateful.

Thanks David

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You've got several options. First, you can use CORS (http://enable-cors.org/) but only if you've got access to the application on the target server.

Alternatively, you can use JSONP (but again, the server must support it): http://www.sitepoint.com/jsonp-examples/.

The last thing that comes into my mind would be using your server as a proxy: call a web service on your server which calls the remote server. This should work as server-to-server communication is not restricted by same origin policy (it's a browser feature).

Also, take a look at this thread: How to make cross domain request


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...