简体   繁体   中英

Ajax call not working in IE7 and FF

I have one js file with a ajax call which is working fine in IE6, but not in IE7 or FF. Can somebody help?

window.onload = function() {
    var xmlhttp;
    var url = "myurl";
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
    debugger;
    alert("Hello");
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        alert("Your browser does not support XMLHTTP!");
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            alert(xmlhttp.responseText);
        }
    }
} 

In IE7 I am getting access denied error. Please help.

EDIT: I am now trying it using jQuery, Code:

$(function() {       
        $.ajax(
                    {
                        type: "GET",
                        url: "myurl",
                        datatype: "html",
                        success: function(xhtml) {
                          $("#con").html(xhtml);
                        },
                        error: function() {
                            displayMessage(......);
                        }
                    });
    });

Still its working in IE6 but not in Others.If its a cross domain issue, then how to solve this?

It might be some security issues. See if it works by adding all url's you use here to the trusted sites list.

IE6 has known bugs/issues when it comes to Javascript and cross-domain policy. This is why (amongst other reasons) that IE6 is no longer being supported in terms of cross-browser compatibility by many large organizations (why encourage something that has such a vulnerability?)

My guess, then, is that your var url = "myurl" is pointing to something on another domain or subdomain. But we need more details to be sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM