A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide
this week in the
How to make synchronous ajax call in cross site domain
Joined: Jan 31, 2011
May 17, 2012 06:13:33
I have to make one synchronous ajax call which solves cross site domain issue.
The ajax call using window.XMLHttpRequest throws error while making call in cross domain.
The ajax call using JSONscriptRequest supports only asynchronous ajax call.
I tried in third way. But it is also not be bale to make synchronous ajax call. Please find the code below:
url = url + '&callback=' + "ACFeedStatistics.callbackSuccess";
var head = document.getElementsByTagName('head');
script = document.createElement('script');
script.id = 'xdShortcutContainer';
script.src = url;
I am totally stuck.
Please help me.
Thanks in advance!!
Joined: Nov 08, 2001
May 17, 2012 07:46:19
same origin policy
prevents it. It is to keep sites from contacting your bank, email, etc.
If the external site is under your control and you only care about modern day browsers, you can look into
If the site is not, only way around it is a serverside proxy on your server to fetch the content.
In reality, synchronous calls are a bad idea since they lock up the browser.
Author and ninkuma
Joined: Jan 10, 2002
May 17, 2012 08:34:37
I agree with Eric. Unless you are able to write a 14-page justification for why the call should be synchronous, it should not be.
And as Eric suggested, you can use a server-side relay to perform the remote request. Or if the remote server supports JSONP, you can make the request directly.
Asking smart questions
Books by Bear
I agree. Here's the link:
subject: How to make synchronous ajax call in cross site domain
Change cursor during Ajax
Cross Site Script error while making AJAX call using Xmlhttprequest
How can I dynamically load js library with document.write inside?
jQuery in Action: Can I use jQuery to go across domains
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015