简体   繁体   中英

javascript not working in IIS

I have page unload javascript that is working fine, but not in IIS ,Do I need to give any permission in IIS for this?Here is my javascript that is not working

window.onbeforeunload = InitializeService;
function InitializeService() {
    InitializeService1();
    if (checkdisposition.disposition == "") {
        var agree =   confirm("You Did Not Save Disposition, Are You Sure You Want To Navigate?");
        if (agree) {
            return true;
        }
        else {
            return "You Did Not Save Disposition ";
        }
    }
}

function InitializeService1() {
    if (window.XMLHttpRequest) {
        var url = "http://localhost:54329/WebServices/PageUnloadCall.asmx?op=Page_Unload";
        myReq.onreadystatechange = checkStatus1;
        myReq.open("GET", url, false); // true indicates asynchronous request
        myReq.send();
    }
}

Most browsers do not allow sending an XMLHttpRequest during the onbeforeunload handler

Also, you should not display a prompt when handling onbeforeunload . You should just return a string if there is unsaved data

From Alexei's answer, my guess is that the real problem is that you were running your page by typing in localhost into the URL bar. But when deployed, you're typing the name of the deployed server. Like Alexei suggested, you should not hardcode localhost in your code. Since it looks like you wanna do it on the client side, you should use https://developer.mozilla.org/en/DOM/window.location

var url = location.host + "/WebServices/PageUnloadCall.asmx?op=Page_Unload";

What are your site's Urls for "non IIS case" and "IIS case"? You could be hitting cross domain restriction when opening Web request to "http://localhost:54329" in IIS case (since site would be different (usually http://localhost:80 ).

Note that as @Juan Mendes pointed out the XMLHttpRequest may not work at all at that time and definitely will not return asynchronous results before page finish closing.

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