Dear all,
I have done a sample program using ajax . But onreadystatechange not working. If i specifies "false" in the open method.

Example program :

<html>
<head><title>Sample Ajax File</title></head>
<script type="text/javascript">
function ajax_function(){
	
		var httpReq = new XMLHttpRequest();

		httpReq.onreadystatechange=function(){
		  alert(httpReq.readyState);
		}

		httpReq.open("GET","http://localhost/ajax/sample.php?name=prem&Id=1",false);
		httpReq.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		httpReq.send(null);
		
}
</script>
<body>
	<form name="frm" action="#" method="" >
		<input type="button" value="Click me" name=""  id="" onclick = "return ajax_function()">
	</form>
</body>
</html>

If i have changed false into true . Then i the function onreadystatechange working.

Note: I am using mozilla browser.

Thank you,

With Regards,
Prem

The tutorial I have the link to, shows the setting as true (the following code is from the link below)

// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		document.myForm.time.value = ajaxRequest.responseText;
	}
}
ajaxRequest.open("GET", "serverTime.php", true);
ajaxRequest.send(null);

http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php

I looked at an old script I had done, and instead of using

httpReq.send(null);

I have

httpReq.send(false);

(not exactly the same variables - but using your code for the syntax examples.) When I have the send set to false, then setting the open to false worked for me at the time and just tested to make sure it still worked.

If setting it to true works for you - it should be fine with your current script. I would just double check that script also works in IE.

Dear macgurl70,

I have changed the false in my statement . Still the code does not works for me.

function ajax_function(){
	
		var httpReq = new XMLHttpRequest();

		httpReq.onreadystatechange=function(){
		  alert(httpReq.readyState);
		}

		httpReq.open("GET","http://localhost/ajax/sample.php?name=prem&Id=1",false);
		httpReq.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		httpReq.send(false);
		
}

Thank you,

Regards,
prem

Why did you change it then? If he one worked for you with the true and null then keep it.

If the setting of "true" and "null" are working - like they do in the link, keep them.

Explanation:

I gave both examples since you had a syntax that is working and has been documented as a viable way to load the information. If one way isn't working, there is a different way to try with different settings that may (usually) has better results.

Dear macgurl70,

I need a solution . I dont accept your answer .

ok, you don't have to. The link I posted is one of many and is a good starting point for you - especially since it matched your original code exactly.

I dont understand why you didn't check the link, did you test it in BOTH IE and Firefox? Or just going by one source of code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.