Jump to content

AJAX get url issue


Dushan69

Recommended Posts

Hello,

 

I am trying to make AJAX get the content from the page http://creativescream.com/html5ws/api/news asynchronously. When i am following the guide by W3SCHOOLS and type exactly the same code but if i just replace the code that goes like:

 

xmlhttp.open("GET","ajax_info.txt",true);

 

into this:

 

xmlhttp.open("GET","http://creativescream.com/html5ws/api/news",true);

 

I get no result. this is my whole code:

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://creativescream.com/html5ws/api/news",true);
xmlhttp.send();
}
</script>
<title>HTML5 WorkShop Gazette</title>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

 

What i really need to make is to use AJAX and JASON to use the info from the link i provided and place them somewhere on the html page. I have a feel like i am missing a step somewhere but I am very new with this AJAX/JASON stuff so I am also finding it a bit hard to understand how those two go together. Any help would be very appreciated.

 

Thanks

Dushan

Link to comment
Share on other sites

I've never done cross-domain AJAX requests before, but I believe you're experiencing a sandbox issue.

 

I've heard of people using JSONP for cross-site AJAX, but I'm not really familiar with the protocol.  Try googling it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.