ltrem Posted July 8, 2009 Share Posted July 8, 2009 Hey guys, I want to know if it is possible to call, with AJAX function, a link that doesn't have the same domain name... Here is the pattern: the page http://www.bla.com is loaded , there is an onclick button that call a Javascript function , in that function, there is some AJAX. The AJAX call a script on a different domain which is that one : https://secure.bla.com Is this possible? Currently not working, and was wondering if it was only possible and if yes, how? Quote Link to comment Share on other sites More sharing options...
corbin Posted July 8, 2009 Share Posted July 8, 2009 The XMLHttpRequest object is coded to not allow requests to a different domain for security reasons. There are ways around it though. The easiest way around it is to just use a framework like jQuery for your AJAX stuff. Quote Link to comment Share on other sites More sharing options...
ltrem Posted July 8, 2009 Author Share Posted July 8, 2009 I'm not sure what you mean exactly, could you be more specific? Would something like this work? http://nodstrum.com/2007/09/19/autocompleter/ Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 9, 2009 Share Posted July 9, 2009 You might want to check out the following url http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback Check out the second example. Notice how it reads a remote flickr url? Quote Link to comment Share on other sites More sharing options...
ltrem Posted July 9, 2009 Author Share Posted July 9, 2009 I tried that getJSON but it's not working... I found something about jsonp... its a headache!! Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 9, 2009 Share Posted July 9, 2009 basicly that second example is jsonp (json with padding). I do think you need access to the server for the script that gives the json response since it's a bit different. The following example I found using google http://a.webvm.net/ you can even see the php source which makes the jsonp possible. If you don't have access to the server you want to use that will output a response, then you're better off using cURL or just any serverside script that can read remote data. With a script like that you could make a remote ajax call a local ajax call. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.