thescientist Posted December 19, 2011 Share Posted December 19, 2011 next task is to alert responseText from external website.oXHR.open("GET", "http://www.ndbc.noaa.gov/station_page.php?station=casm1/", true); is not going to work. AJAX in browsers is not allowed cross domain like that. The most common solution is to make an AJAX request to a server side script (proxy) that can make a cross domain request for you and return the response. Ways to do this in PHP are with HTTP or cURL. I usually use cURL. Link to comment Share on other sites More sharing options...
paulmo Posted December 19, 2011 Author Share Posted December 19, 2011 I did use PHP for similar a couple years ago but lost the code. Plus it was using YUI library so I really didn't know what I was doing. But I did have a proxy page. So I can't do this in JS? here's example from mozilla which has a web url in it: var oXHR = new XMLHttpRequest();oXHR.open("GET", "http://www.mozilla.org/", true);oXHR.onreadystatechange = function (oEvent) { if (oXHR.readyState === 4) { if (oXHR.status === 200) { console.log(oXHR.responseText) } else { console.log("Error", oXHR.statusText); } }};oXHR.send(null); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.