(12-19-2009, 03:08 PM)Rob Wrote: Could you give me an example of some code I would use?
So here you go, there is a php script that loads the content of a given website, in this case it's a google.com
PHP Code:
<?php
$content = file_get_contents("http://www.google.com/");
$matches = null;
preg_match_all("/<title>(.*?)<\/title>/", $content, $matches);
echo $matches[1][0];
?>
The preg_match function will search for the title of the loaded content and it will echo it
Now the ajax, the code is taken from w3 and I edited few lines...
Code:
<html>
<body>
<script type="text/javascript">
function ajaxFunction()
{
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)
{
document.getElementById("content").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","extern.php",true);
xmlhttp.send(null);
}
</script>
<div id="content" onclick="ajaxFunction();">
a
</div>
</body>
</html>
When you click on the div, the ajaxFunction will load extern.php.... and update the inner html of the div.