简体   繁体   中英

Change is not displayed on page refresh while using IE8

I have written some JavaScript functions that will do 2 things when a button is clicked:

  1. It will change the label of the button to "Deactivate" from "Activate" and vice versa.
  2. The value of the ActiveStatus property will change to 0 from 1 and vice versa.

The code works alright and the change is displayed perfectly in Mozilla Firefox, but whenever I try display the page in IE 8, change is not displayed, although in database, the value changes perfectly.

Here are the JavaScript codes for the button click:

$(function () {


    var stat = document.getElementById("stat").value;
    //alert(stat);

    if (stat == 1)
        document.getElementById("butt").value = "Activate";
    else
        document.getElementById("butt").value = "Deactivate";
});




function activeStatus(ActiveStatus) {

    //alert(ActiveStatus);
    if (ActiveStatus == 1) {
        return "Activate";
    }
    else
    return "Deactivate";
}

function change() {

    var butt = document.getElementById("butt").value;

    if (butt == 'Deactivate') {
        document.getElementById("butt").value = "Activate";
        document.getElementById("stat").value = 1;
    }

    else {
        document.getElementById("butt").value = "Deactivate";
        document.getElementById("stat").value = 0;
    }
}

Also, an exception message I'm getting whenever I'm trying to view the page in IE 8 is:

Microsoft JScript runtime error: Object doesn't support this property or method

I'm getting this error at the Country.js JavaScript file. The place where I'm getting this exception is:

var url = "/Country/GetAllCountry";
    var refresh = function () {
        $.getJSON(url, {}, function (data) {
            self.Countries(data);
        });
    };

More specifically, in this line:

self.Countries(data);    

None of these happen, when I try to run my application in Firefox. All these happen when I try to run my application in IE 8.

Why am I facing this problem????

EDIT-1: I solved my problem partially. The exception:

Microsoft JScript runtime error: Object doesn't support this property or method

was displayed only because 'Countries' was undefined in Country.js. Countries must be a valid observable, but it has to be declared. I simply had to add this line of code next to it, doing the declaration:

self.Countries = ko.observableArray([]);

Now the exception has disappeared, still the page is not refreshed after the button click.

The answer to this problem is in these 5 simple steps:

  1. Select Tools >> Internet Options.
  2. Click the Settings button in Browsing History.
  3. Select the Every time I visit the webpage radio button.
  4. Click OK to close the Settings dialog.
  5. Click OK to close the Internet Options dialog.

It works perfectly now.

Courtesy: Gonzalo ( https://stackoverflow.com/users/203766/gonzalo )

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