PDA

View Full Version : how to access cross domain in JSON


hannahwill
05-08-2009, 02:32 PM
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--------------

window.onload=makeRequest;

function makeRequest()
{
var http_request={};
if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
http_request = new XMLHttpRequest();
}
else
{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}

http_request.open("GET", "http://www.uclocal.com/LX-U.aspx?", false);
http_request.onreadystatechange=function()
{
if(http_request.readyState==3)
{
alert("data is loading...please wait");
}
else
if(http_request.readyState==4)
{
if(http_request.status==200)
{
document.write(http_request.responseText);
}
}
}
http_request.send();
}
:thumbsup:

A1ien51
05-08-2009, 04:07 PM
You can not use the XMLHTTPRequest object on different domains.

If the other domain is returning back JSON you can you the script tag method.

Example here using Yahoo's JSON Webservice:
http://www.pascarello.com/examples/JsonYahooExample.html

Eric

Kor
05-12-2009, 04:58 PM
Well... you can use the XMLHTTPRequest to send a request to a server-side application (on the same domain) which is able to perform a cross-domain request.

For instance here is a (tested) AJAX & PHP cross-domain request solution: http://www.troywolf.com/articles/

Should be similar solution with ASP, Java, Pearl...

itsallkizza
05-12-2009, 05:00 PM
OP: If you tell us what server-side languages you have available (php/asp/jsp) I can write you a steal-page script that will accept a url as the only parameter and output that page's contents. It will allow you to ajax any page on the internet no problem.

hannahwill
06-18-2009, 06:00 PM
i am using visual basic asp .net as server side programming.
itsallkizza! i am still stuck with this problem.

any help would be appreciated
thanks

itsallkizza
06-19-2009, 04:52 PM
I wrote a "steal_page.asp" for you. You can use JS to ajax this page, passing along the url of the page you want to grab. You can now ajax any page on the internet using JS and steal_page.asp:

<%@ language="javascript"%>
<%

var url_to_steal = String(Request.QueryString("page_url"));
if (url_to_steal.charAt(0) == '"') url_to_steal = url_to_steal.substring(1,url_to_steal.length-1);

if (!url_to_steal) Response.Write("null");
else
{
var xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0");
xmlhttp.open("GET",url_to_steal,false);
xmlhttp.send("");
Response.Write(xmlhttp.responseText);
xmlhttp = null;
}

%>


For an example, you can grab google.com from your JS by ajaxing this url: /steal_page.asp?page_url=http://www.google.com
(or) /steal_page.asp?page_url="http://www.google.com"

manishbht
06-29-2009, 09:55 PM
hello I have this banner which contains a geo tracked advertisement which i want to run in a flash player. I just want to be able to embed page (http://somepage.com/advertisement.php) in the flash player. can somebody help me with this?
thanks