Friday 22 November 2013

AJAX Checking responceText value

Posted by Саша 19:24, under | No comments


AJAX Checking responceText value? AJAX Checking responceText value?

Here is basic AJAX:

Where is the actual value of the response located?

// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}

var ajaxRequest = new XMLHttpRequest();
var queryString = "?check=" + data;
ajaxRequest.open("GET", "ajax-example.php" + queryString, true);
ajaxRequest.send(null);

ajax-example.php has php to add the value of ?check= to database, if the database already has it, it echos a number 1. This the number 1 is placed into the block element of the id 'ajaxDiv' on my page. From what I understand and by looking at the code 'ajaxRequest.responseText' is that value and is what is placed into ajaxDiv.

I want to do this in the javascript instead of putting a 1 on the page.
if (ajaxRequest.responseText == 1)
alert("duplicate")

but it doesn't work.


Other Answers:













0 коммент.:

Post a Comment