jQuery GET not reading HTML response data in IE

2019-07-05 05:47发布

问题:

I'm doing a pretty simply ajax call using jQuery (in Wordpress) - using GET to fetch the contents of a page, then reading the response into a jQuery object. This works fine in every browser except IE8 (not concerned about IE6/7. The relevant code is identical to what I have used in previous sites, all of which work in IE8. Here's the code:

var ajax_params = {
url: relative_url,
type: 'GET',
dataType: 'html',
data: {},

success: function(data, textStatus, xhr) {

     // create jquery element from html string
    data = $('<div/>').append(data);

    pre($(data).find('#content'));
    pre($('#content'));

    plugin.replace_content(data, relative_url);

},

};

plugin.ajax_call = $.ajax(ajax_params);

The pre() functions are just calls to console.log, and I'm using firebug lite in IE8 to debug. I've determined that the ajax call is working, and the HTML of the requested page is being returned successfully in the data variable. It's getting hung up on data = $('<div/>').append(data), where the result is an empty div. As I said, this exact code works on other sites, so I'm at a loss to explain this. I've downgraded the jQuery version to 1.8.3 to match what is on the other sites to no avail.

Any ideas?

回答1:

We figured out the problem: it was a memory issue, caused by the ajax response being too large for IE to parse. This would explain why the exact same method on other sites worked. We fixed it by stripping out as much as possible from the response html. Another solution would be to split the response data into chunks and make multiple ajax requests.



回答2:

yes it true. IN IE8 if response is too large then ajax call is not working. to work with IE8 we have to reduce the content which we are getting from the ajax call.