Ajax in Script Editor does not fire until I open the developer tools for Internet Explorer

I have a very weird issue that is occurring with jquery code that I put in a Script Editor web part. In IE 9 and below the code does not seem to run if you just open up the browser to the page that contains the webpart. If you then open up the IE developer tools and then hit refresh the code runs and executes perfectly. And when I say code doesn't run I mean nothing at all shows in the web part just the title of the Script Editor and that's it.

No issues at all when run in Chrome and Firefox. The whole thing with the developer tools part is just blowing my mind I don't get why it will run when you have open that but won't run when you haven't opened them. Any help would be appreciated.

    <div id="leaveBalance"></div>
    <script type="text/javascript">
        (function () {
            jQuery(function ($) {
                $.ajax({
                    dataType: "json",
                    timeout: 3500,
                    cache: false,
                    url: "GetLeave.aspx"
                }).done(function (data) {
                    processData(data);
                }).fail(function () {
                    failedLoad();
                });
            });

            function processData(data) {
                var testing = "testing";
                var sickLeave = data.U_ALT_JSON_DATA.U_ALT_RESP[0];
                var annualLeave = data.U_ALT_JSON_DATA.U_ALT_RESP[1];
                var leaveTable = $('<table>').append(
                        $('<tr>').append(
                            $("<th colspan='2'>").text("Annual Leave")
                        ),
                        $('<tr>').append(
                            $("<td>").html("Hours Balance <i>(as of " + annualLeave.Resp_accrual_end_dt + "</i>)"),
                            $("<td>").text(annualLeave.Resp_hrs_bal)
                        ),
                        $('<tr>').append(
                            $("<td>").text("Hours Adjusted"),
                            $("<td>").text(annualLeave.Resp_hrs_adj)
                        ),
                        $('<tr>').append(
                            $("<td>").text("Hours Requested"),
                            $("<td>").text(annualLeave.Resp_hrs_req)
                        ),
                        $('<tr>').append(
                            $("<td>").html("Hours Available <i>(as of " + annualLeave.Resp_accrual_end_dt + "</i>)"),
                            $("<td>").text(annualLeave.Resp_hrs_avail)
                        ),
                        $('<tr>').append(
                            $("<th colspan='2'>").text("Sick Leave")
                        ),
                        $('<tr>').append(
                            $("<td>").html("Hours Balance <i>(as of " + sickLeave.Resp_accrual_end_dt + "</i>)"),
                            $("<td>").text(sickLeave.Resp_hrs_bal)
                        ),
                        $('<tr>').append(
                            $("<td>").text("Hours Adjusted"),
                            $("<td>").text(sickLeave.Resp_hrs_adj)
                        ),
                        $('<tr>').append(
                            $("<td>").text("Hours Requested"),
                            $("<td>").text(sickLeave.Resp_hrs_req)
                        ),
                        $('<tr>').append(
                            $("<td>").html("Hours Available <i>(as of " + sickLeave.Resp_accrual_end_dt + "</i>)"),
                            $("<td>").text(sickLeave.Resp_hrs_avail)
                        )
                    );
                $("#leaveBalance").html(leaveTable);
            }

            function failedLoad() {
                var testig = "testing";
                $("#leaveBalance").html("There was an issue displaying your data.");
            }
        })();
    </script>



  • Edited by jlehmanusf Thursday, February 26, 2015 8:05 PM
February 26th, 2015 8:03pm

I only had IE 9 at work so I just tested in IE 11 and no issues at all. This code works perfectly. And I realized I wasn't clear on how I get it to run in IE 9. I went to troubleshoot if I was getting any errors because usually if the jquery is in the webpart  and it is firing before it loads you get a console error saying that jquery is not loaded. So in IE 9 I opened up the developer tools and refreshed and the code runs as expected. There is something about when the developer tools getting activated that makes IE 9 run it correctly. Also if jquery wasn't loading shouldn't also not run in other browser like Chrome and Firefox. As I mentioned above it runs fine in those browsers.

Free Windows Admin Tool Kit Click here and download it now
February 27th, 2015 12:41pm

Hi, Please Check if any of your JavaScript functions using console.log() or console.debug() statements and comment it out.
March 1st, 2015 3:41am

Using console.log and console.debug doesn't help me because as soon as I open up the developer tools to see what was written out by the script, the script runs as expected. This is what I can't figure out. If developer tools are turned off the jquery script does not run. As soon as the developer tools are turned on in IE 9 and below the jquery executes.
Free Windows Admin Tool Kit Click here and download it now
March 9th, 2015 8:41pm

Shouldn't this also be an issue in Chrome, Firefox and IE 10 and 11? It executes perfectly there. Also if this was the issue why does IE 9 and below run the code as soon as the developer tools are open? The code shouldn't run then either. Again the thing that is confusing me is the code executes perfectly in IE 9 and below when the developer tools are open. To me if the code was bad the code shouldn't run at all whether the tools are open or not.
March 9th, 2015 8:44pm

I dismissed this to fast. I don't understand it but this fixed it in IE 9 and below. I still don't understand why the other way worked for IE 10 and above, Chrome and Firefox and IE 9 and below had an issue. Still would love to hear if anyone has an explanation.
Free Windows Admin Tool Kit Click here and download it now
March 9th, 2015 9:18pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics