0

I have tested following code and it works fine in IE but not Mozilla:

var ajax = false;

if (window.XMLHttpRequest) {
ajax = new XMLHttpRequest();
}
else if (window.ActiveXObject) {


try {
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
}

catch (e1) {

try {
    ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {}
}
}

if (!ajax) {
alert ('Some page functionality is unavailable.');
}

Please tell me what is the solution?

Edited by mike_2000_17: Fixed formatting

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by fawad123
0

Hi, save yourself time and code lines using a library. top developers has done the hard work sniffing browsers and such.

I can recomen jQuery, so your can use an ajax request that is crossbrowser with a single line of code:

$.ajax(url, data, callback)

HTH

0

What "doesn't work" about your code? I cut and pasted it in firebug and it runs just fine. I see the XMLHttpRequest object in the console window.

Edited by scrappedcola: n/a

0

This is my code

php Syntax (Toggle Plain Text)

for ($i=0; $i<length; $i++)
{
    echo '<textarea type="text" name="username' . $i .
         '" cols="60" rows="4" onkeydown="check_username('. $i .')">' .
         $sentences_data[$i] . '</textarea> <span id="username_label' . $i .
         '"></span><br/>';
}

javascript Syntax (Toggle Plain Text)

function check_username(index) {
    if (!ajax) {
        alert("ajax not created");
        return;
    }
    var username = document.getElementById("username" + index);
    ajax.open("get", "testuser.php?id=" + username);
    ajax.onreadystatechange = function() { handle_check(index); };
    ajax.send(null);
}

// Passing index to this function allows access to correct username_label element.
function handle_check(index) {
    if (ajax.readyState == 4 && ajax.status == 200) {
        document.getElementById("username_label" + index).innerHTML = ajax.responseText;
    }
}

This works fine in Internet Explorer but nothing happens on Mozilla. Please suggest me where is the mistake?

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.