Hey guys i want to get data from external php file using AJAX (different domain name) var myRand2; myRand2=parseInt(Math.random()*99999); var url="http://www.thegirlz.net/chat/mainTXT.php?wadwij="+myRand2; xmlHttp2.onreadystatechange=stateChanged22 xmlHttp2.open("GET",url,true) xmlHttp2.send(null) var objDiv = document.getElementById("mainTXT"); Code (markup): just a part of my code i get error "permisson denied" when using this URL looks like browsers have default protection against requesting data from external files from JS code. But is there any way (like editing header sent) or anything that would allow me to override this? thanks for your answers. (i'll explain anything you don't understand (my english sux))
Make a PHP file to get the data from the "external PHP" and link it to your ajax script, that should do the job.
yeah i was thinking about that too. But i'm actualy working on a script that will be remote hosted so users will only have to include a single line of code into their site. Everything else loads from my site. So that is not an option (and it's probably the only way it could work ).
When I need to contact a remote URL with AJAX, I use the following XML_Proxy.php <?php header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $url = "http://www.weather.gov/data/current_obs/"; $url .= $_GET['code']; $session = curl_init($url); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $xml = curl_exec($session); header("Content-Type: text/xml"); echo $xml; curl_close($session); ?> Code (markup): The AJAX function contacts XML_Proxy.php, and the proxy file contacts the remote URL. The remote URL responds to the proxy, the proxy responds to the AJAX function.
well thanks for your replays i'll go with this proxy script for now. We'll see how it goes. I'll probably have to find some other solution but it'll work for now