Question Details

Browse

Ajax Cross Domain Request

By Muhammad Abid - Sep. 03, 2008

i want to use ajax for cross domain request calls? can any one help me
or send me an example code?

my front end widget can only have HTML and Javascript and i need to fetch data from different server.

and this HTML and Javascript front end code can be placed on any server. and i need to send ajax call from it. but it dont work by me. can any one help?


Answers

Add Answer
  1. By an anonymous user on Sep. 03, 2008

    Can you make an API available from the server that your javascript can call?


    Alternatively, you can check out this resource:

    http://www.ajaxlessons.com/2006/02/14/cross-domain-ajax-using-prototypej...


    You might want to get a library like prototype.js to help with this.


    By default, you are not able to do this due to security concerns. See this link:


    http://en.wikipedia.org/wiki/Same_origin_policy


    0 Votes
  2. By an anonymous user on Sep. 03, 2008

    making an API public, means i have to write a web service? right?


    but i have no prior knowledge of writing web services


    http://www.ajaxlessons.com/2006/02/14/cross-domain-ajax-using-prototypej...


    I tried this modified version of code, but it did not work for me...might be this solution needs some extra setting that i don't know..


    0 Votes
  3. By Jesse Babson on Sep. 03, 2008

    Heheh - this has been explicitly been prevented because of security concerns. You can expect to get an error "Error: uncaught exception: Permission denied to call method XMLHttpRequest.open". But, there are several ways around this. One way is to bypass this directly by writing a php file on your server and have that fetch the information from the other domain, and pass in the required parameters from there.


    1 Votes
  4. By an anonymous user on Sep. 03, 2008

    the problem is, my HTML, JavaScript code is for a widget, and any one can add this code in any site, that could be PHP, ASP, java, or any technology based site.


    so i have to strictly depend on Java Script and HTML for fetching data from server.


    0 Votes
  5. By an anonymous user on Sep. 03, 2008

    Guys from w3c are currently working on the standart for cross-domain request, so just have to wait.... a year... or two? :)


    However there are some workarounds that don't even require to write your own webservice-wrapper on the same domain from where your page came: you can do async-request with some different technique from XHR. You can use a hidden IFRAME or something like that. Ugly but works. Take a look at YUI, I heard that their "ajax" has features to process requests in such way


    0 Votes
  6. By Kyle Simpson on Jun. 09, 2009

    You might want to check out flXHR http://flxhr.flensed.com


    It's a cross-domain Ajax solution entirely client side. It implements an identical API to native XHR object, so your other existing code doesn't have to change any. In fact there are plugins for jQuery, Dojo, and Prototype already.


    flXHR is the easiest way you can get truly cross-browser, cross-site, cross-platform, cross-domain Ajax.


    1 Votes
Share your knowledge