简体   繁体   中英

How to make cross domain request using ajax or javascript?

I have some Pre built script that makes some ajax request to one website. And it's working fine. But I am not able to make request to there some domains.

My working Process:-

1) I have pre built script on http://www.Test.com/a.js now i am calling this js in this domain http://www.test1.com by pasting the code to URL and it's working fine.

2) Now When I want to call one page from This http://hello.test1.com/as.php but it's showing some errors. How could i make request to subdomain page from main domain page.

Please let me know how can i do this.

Thanks in advance.

Your various options for cross-domain requests are:

  • The new Cross-Origin Resource Sharing (CORS) standard, if the browsers your users use support it and the server has support for it. Note that a lot of general web users still have browsers that don't support it.
  • JSON-P ("JSON with padding"), which is basically a dynamically-added script element
  • Using YQL (Yahoo Query Language) as a cross-domain proxy

There are several work arounds for cross domain scripting restrictions. easyXDM seems to do what you want.

You can use php curl to do the cross domain request using ajax. An ajax request will call php curl page which in turn will call cross domain with url specified in php curl page and return back the response .

I have implemented same and it works fine. Hope this helps Thanks.

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