Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX and IE - Unable to get property error

I'm getting the following error Unable to get property ‘replace’ of undefined or null reference on line var ajax_html = $(xml).find("#search-ajax-content").html(); when using AJAX on IE (testing in IE11). This code is functioning fine on other browsers (Chrome, FF, and Safari).

Has anyone ever experienced this issue before using AJAX? I'm not exactly sure how to resolve this issue. Any help is appreciated! Thank you!!

    $.ajax({
            type:"GET",
            dataType:"xml",
            url:"/search-ajax/" + window.location.search + "&pagination=" + page,
            success: function(data) {
                var xml = data;

                if (page == 1)
                {
                    $("#wait-element-container").remove();


                    // Issue is happening here only on IE!
                    var ajax_html = $(xml).find("#search-ajax-content").html();
                    $("#postload-target").append(ajax_html);
                }

            }
        });
like image 771
Michael Avatar asked May 25 '18 16:05

Michael


1 Answers

jQuery is able to parse text and query as HTML (as long as the text is valid html). Have you tried:

$.ajax({
            type:"GET",
            dataType:"text",
            url:"/search-ajax/" + window.location.search + "&pagination=" + page,
            success: function(data) {
                var xml = data;

                if (page == 1)
                {
                    $("#wait-element-container").remove();


                    // Issue is happening here only on IE!
                    var ajax_html = $(xml).find("#search-ajax-content").html();
                    $("#postload-target").append(ajax_html);
                }

            }
        });
like image 168
malkassem Avatar answered Nov 04 '22 19:11

malkassem