1

I have a global ajax success function set up to detect an ajax submission on a wordpress page. Depending on the result, I would like to convey the response text to the user on the page. Usually I would just create the ajax post myself, and simply write any response to the screen with my own function - i.e.:

success : function(data) {
            theResult = data;
            if (data.indexOf("the response I'm looking for") > -1 ) {
                $(".targetdiv").append(data');
            }
}

But, this ajax request is performed by a wordpress plugin, which I do not want to modify and thus lose any modifications when the plugin is updated. So I found this general ajax success function:

$(document).ajaxSuccess(function(event, request, options) {
    var data = request.responseText;
    if (data.indexOf("the response I'm looking for") > -1 ) {
        $(".targetdiv").append(data');
    }
});

This works perfectly in Firefox and Chrome, and MS Edge Browser, but not in any earlier versions of IE including 9, 10 & 11 or earlier versions of Safari (8 and earlier).

It fails in those browsers by not getting the request.responseText at all.

I did some testing trying this: $parseJSON(request.responseText) to no avail.

I was just wondering what is different about the earlier versions of Explorer and Safari that would cause this to not work in those browsers.

deeholzman
  • 189
  • 1
  • 3
  • 15
  • [Possibly useful](http://stackoverflow.com/questions/782532/ie-not-triggering-jquery-ajax-success) – Draco18s no longer trusts SE Jan 21 '16 at 19:54
  • inspect the `request` object in console for clues using breakpoint, debugger or logging – charlietfl Jan 21 '16 at 20:09
  • @charlietfl by inspecting the request object in console I found nothing wrong with the ajax request object, no errors, etc. so that forced me to look at all of the other scripts/objects on the page, and found that an error in a Jquery datetimepicker script was preventing safari and IE from running any other jquery script on the page, hence the problems with the ajax request problem. The datetimepicker was functioning perfectly in FF and Chrome so it was impossible to see the error in either of those browsers. Should have examined the safari and IE errors more closely – deeholzman Jan 21 '16 at 21:05
  • 1
    hate to say this but that's always the first thing to look for – charlietfl Jan 21 '16 at 21:07
  • Yes definitely I was totally relying on my favorite firefox console to tell me what was right in front of me via the other browser consoles - duh - lesson learned and thanks for inspection of object in console suggestion. – deeholzman Jan 22 '16 at 00:00

1 Answers1

0

The global ajax success function wasn't working in IE and Safari because there was another unrelated script causing problems in those browsers that stopped ALL JQuery functions from working.

I was relying on FF console which wasn't giving me details on errors found in IE and Safari. An obvious thing that I should have caught initially but I guess the lesson here is to not rely on one browser console to troubleshoot errors occurring in other environments.

deeholzman
  • 189
  • 1
  • 3
  • 15