0

Good day, I'm having a problem with an ajax query, but when the response is like 4090+ characters lenght then the jQuery ajax function just fails and runs the error function, here is my code:

function loadContent( e) {

currentActiveSlide = e;

    var parametros = {
            "action"    : 'slideContent',
            "rel"       : e.attr('rel'),
    };

    jQuery.ajax({
                data:  parametros,
                url:   template_url + '/ajax.php',
                type:  'post',

                success:  function (response, e) {
                   //What ever...
                },
                error: function(xhr, status, error) {
                    alert(error);
        }
    });
}

It doesn't matter what the response data is, I tried adding the 'a' characters 4k+ times and it launchs the error function with the error variable empty.

Any suggestion? - Thanks in advance!

Added data:

It doesn't matter which data is, if for example I send as response the character 'a' more than 4k times 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...' then the function will NOT work, if there are less than 4k then it will work as it should work, but will not if more than 4k characters, so I think there is a limit in the response variable or something like that.

Ultranuke
  • 1,735
  • 2
  • 15
  • 21

2 Answers2

0

From jQuery ajax docs:

success

Type: Function( PlainObject data, String textStatus, jqXHR jqXHR ) A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.

So I believe jQuery(e).html(..) is wrong because e is a status string not a selector (you are in the scope of the success function so the e var you had before is inaccessible - you defined another var with same name).

You should use currentActiveSlide.html(..) instead.

Yotam Omer
  • 15,310
  • 11
  • 62
  • 65
0
function loadContent(e) {
    currentActiveSlide = e;
    var parametros = {
            "action"    : 'slideContent',
            "rel"       : e.attr('rel')
    };
    jQuery.ajax({
            data:  parametros,
            url:   template_url + '/ajax.php',
            type:  'post'
    }).done(function(data, textStatus, jqXHR) {
            alert(jqXHR.responseText);
    }).fail(function(jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
    });
}

See changes made to your script. You have an extraneous comma in your parametros variable declaration. Also, your success and error methods do not respond in the format you have laid out.

However, to your point -- This question is very much like this one: What is max size of ajax response data?. And this one: What is the maximum possible length of a query string?

Community
  • 1
  • 1
DevlshOne
  • 8,357
  • 1
  • 29
  • 37