Wassini
asked on
Ajax onReadyStateChange problem
I have two functions:
I have tested in IE + Chrome
Any clue?
Btw: The ASP file is just a dummy:
response.write "OK"
Ajax: this is working!
With a handler (onReadyStateChange). This is NOT working! It only calls the handler function once with no status or readyState!
I have tested in IE + Chrome
Any clue?
Btw: The ASP file is just a dummy:
response.write "OK"
<script>
function Ajax() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "test.asp", false);
xmlHttp.send();
alert("Ajax:" + xmlHttp.responseText);
}
function DynAjax() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "test.asp", true);
xmlHttp.onReadyStateChange = handler();
xmlHttp.send();
}
function handler() {
if(this.readyState == 4 && this.status == 200) {
alert("DynAjax: " + this.responseText);
}
}
</script>
Hi, try this.
The problem is
xmlHttp.onReadyStateChange instead of xmlHttp.onreadystatechange
and
handler(); instead of handler;
The problem is
xmlHttp.onReadyStateChange
and
handler(); instead of handler;
<script>
function Ajax() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "default.asp", false);
xmlHttp.send();
alert("Ajax:" + xmlHttp.responseText);
}
function DynAjax() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = handler;
/*xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert("DynAjax: " + this.responseText);
}
};*/
xmlHttp.open("GET", "default.asp", true);
xmlHttp.send();
}
function handler() {
if(this.readyState == 4 && this.status == 200) {
alert("DynAjax: " + this.responseText);
}
}
</script>
or this
function DynAjax()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "test.asp", true);
xmlHttp.onReadyStateChange =function()
{
handler(xmlHttp);
}
xmlHttp.send();
}
function handler(xmlHttp)
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
alert("DynAjax: " + xmlHttp.responseText);
}
}
try this
xmlHttp.onreadystatechange = handler();
xmlHttp.onreadystatechange
ASKER
Arsenico/ddsh79: If I change to onreadystatechange instead of onReadyStateChange, IE 8 reports: "Not implemented"
gurvinder372: This does nothing either! Same problem!
gurvinder372: This does nothing either! Same problem!
what is error? on which line?
this also?
this also?
function DynAjax()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "test.asp", true);
xmlHttp.onReadyStateChange =function(xmlHttp)
{
handler(xmlHttp);
}
xmlHttp.send();
}
function handler(xmlHttp)
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
alert("DynAjax: " + xmlHttp.responseText);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Strange! I have another PC where I can call the handler WITH parameters... But apparently not on this PC! (???)
But thanks!
But thanks!
function DynAjax()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "test.asp", true);
xmlHttp.onReadyStateChange
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert("DynAjax: " + xmlHttp.responseText);
}
}
xmlHttp.send();
}