First you have to make a script in PHP to query the database with the value passed from the script below and then give an output in the script by using either print or echo. In the page that you want to pass the value back to the script you need to add the following....
<script language="JavaScript1.2" type="text/javascript">
function makeRequest(url) {
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
httpRequest.open('GET', url, true);
httpRequest.send('');
}
// Function to deal with returned request
function alertContents(httpRequest) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
changeText(httpRequest.responseText);
//alert(httpRequest.responseText);
} else {
alert('There was a problem with the request. '+httpRequest.status);
}
}
}
Then with is in the page you only have to make your own function in JS to deal with the reply back from your script on the webserver.
function changeText(){
// This is were you put your script to handel if it is the same or not.
}
</script>