how to access cross domain in JSON

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2009
Posts: 8
Reputation: hannahwill is an unknown quantity at this point 
Solved Threads: 0
hannahwill hannahwill is offline Offline
Newbie Poster

how to access cross domain in JSON

 
0
  #1
May 8th, 2009
hello

Question:

i get "Access denied" error.Can anyone convert the code below in JSON i need to access data from some other domain. OR any other fully explained efficient method to access cross domains plz.

---------js file--------------

  1. window.onload=makeRequest;
  2.  
  3. function makeRequest()
  4. {
  5. var http_request={};
  6. if (window.XMLHttpRequest)
  7. { // Mozilla, Safari,...
  8. http_request = new XMLHttpRequest();
  9. }
  10. else
  11. {
  12. http_request=new ActiveXObject("Msxml2.XMLHTTP");
  13. }
  14.  
  15. http_request.open("GET", "http://www.uclocal.com/LX-U.aspx?", false);
  16. http_request.onreadystatechange=function()
  17. {
  18. if(http_request.readyState==3)
  19. {
  20. alert("data is loading...please wait");
  21. }
  22. else
  23. if(http_request.readyState==4)
  24. {
  25. if(http_request.status==200)
  26. {
  27. document.write(http_request.responseText);
  28. }
  29. }
  30. }
  31. http_request.send();
  32. }
Last edited by peter_budo; May 9th, 2009 at 12:58 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,410
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 227
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: how to access cross domain in JSON

 
0
  #2
May 8th, 2009
It's a security feature on browsers, cross-domain AJAX isn't allowed and would be a big issue if it was. If you need to get data from another website use an AJAX call to call a local file which uses cURL or something similar to fetch the file.
Last edited by ShawnCplus; May 8th, 2009 at 2:41 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC