Rich
Rich

Reputation: 4170

IE not activating Ajax

I have the following script on my page, in Chrome, it works perfectly, but IE is not getting into the success{} function of Ajax. It goes into the Complete{} function perfectly fine. When I tried to send the data variable through the Complete{} function, it just displays an [object Object] as the contents. What can I do to get this to function in IE?

$(document).ready(function () {
    var totalstrings = "";
    var totaltimes = "";
    var trendstop = "false";
    var firstrun = "true";
    var url = "newtrend.aspx";
    $('#fm1').attr('src', "http://somepage/page1/collecttrend.aspx");

    (function worker() {
        var rand;
        $.ajax({
            url: 'http://somepage/page1/gettrendvars.aspx',
            success: function (data) {
                if (totalstrings.length < data.length || data === "") {
                    alert("test1");
                    if (trendstop === "false") {
                        alert("test2");
                        var iframe = document.getElementById("fm1");
                        iframe.src = iframe.src;
                        totalstrings = data;
                    }
                    if (data === "") {
                        trendstop = "true";
                    } else {
                        trendstop = "false";
                    }
                }
            },
            complete: function (data) {
                setTimeout(worker, 10000);
                $.ajax({
                    url: 'http://somepage/page1/gettimevars.aspx',
                    success: function (data) {
                        if (totaltimes != data) {
                            var iframe = document.getElementById("fm1");
                            iframe.src = iframe.src;
                            totaltimes = data;
                        }
                    },
                    complete: function (data) {
                    }
                })();
            }
        });
    })();
});

Upvotes: 0

Views: 65

Answers (2)

Rich
Rich

Reputation: 4170

Finally got it to work, in conjunction with Vinicius Souza's answer. Utilizing the $.get() command rather than the ajax(), and activating the timestamp to break the caching of IE.

Thanks Everyone!

(function worker() {
    var rand;
    $.get("http://somepage/page1/gettrendvars.aspx?timestamp=" + new Date().getTime(), {})
        .done(function (data) {
        if (totalstrings.length < data.length || data === "") {
            if (trendstop === "false") {
                var iframe = document.getElementById("fm1");
                iframe.src = iframe.src;
                totalstrings = data;
            }
            if (data === "") {
                trendstop = "true";
            } else {
                trendstop = "false";
            }
        }

        $.get("http://somepage/page1/gettimevars.aspx?timestamp=" + new Date().getTime(), {})
            .done(function (data) {
            if (totaltimes != data) {
                var iframe = document.getElementById("fm1");
                iframe.src = iframe.src;
                totaltimes = data;
            }
        });
    })
        .fail(function () {
    });
    setTimeout(worker, 1500);
})();

Upvotes: 0

Vinicius Souza
Vinicius Souza

Reputation: 151

Try adding a timestamp to your ajax requests, for some reason, IE caches it sometimes.

    $.ajax({
        url: 'http://somepage/page1/gettrendvars.aspx?timestamp='+ new Date().getTime(),
        success: function (data) {
            if (totalstrings.length < data.length || data === "") {
                alert("test1");
                if (trendstop === "false") {
                    alert("test2");
                    var iframe = document.getElementById("fm1");
                    iframe.src = iframe.src;
                    totalstrings = data;
                }
                if (data === "") {
                    trendstop = "true";
                } else {
                    trendstop = "false";
                }
            }
        },
        complete: function (data) {
            setTimeout(worker, 10000);
            $.ajax({
                url: 'http://somepage/page1/gettimevars.aspx?timestamp=' + new Date().getTime(),
                success: function (data) {
                    if (totaltimes != data) {
                        var iframe = document.getElementById("fm1");
                        iframe.src = iframe.src;
                        totaltimes = data;
                    }
                },
                complete: function (data) {
                }
            })();
        }
    });

Upvotes: 1

Related Questions