Kyle Cureau
Kyle Cureau

Reputation: 19366

On JQuery AJAX POST...request failed: URI too long (longer than 8190)

I got the error:

request failed: URI too long (longer than 8190)

I've seen other posts on StackOverflow for this one. Those posts recommend:

I'm using jQuery's AJAX to POST:

    $.ajax({
        url: "test.php",
        dataType: "json",
        data: paras,
        type: "POST",
        success: function(ret){callback(ret);}
    });

It's my impression you can use json just not jsonp. Correct? If so, why might I still be getting the error?

Upvotes: 3

Views: 14006

Answers (2)

Andrew Faulkner
Andrew Faulkner

Reputation: 3930

I ran into this issue when using jQuery to submit large forms, and was able to solve it by adding this plugin.

For example, using the following code to submit the form after adding the plugin resolved the issue for me:

    $(formSelectorHere).ajaxSubmit({
        url: myURL,
        type: 'post',
        contentType: "multipart/form-data",
        data: $(this).serialize(),
        success: function(data) {
        function(data) {
            //success code here//
        }
    });

If you're not using this to submit a form, this may not be relevant to you and won't solve your problem, but that's the most common situation where this issue appears, so I figured it was worth mentioning. (The plugin should also be able to submit a form using JSON, but haven't personally tested it).

Upvotes: 0

Dane O'Connor
Dane O'Connor

Reputation: 77298

You should try setting proccessData to false.

From the docs:

By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false.

so to prevent the data being added to the url:

$.ajax({
    url: "test.php",
    dataType: "application/json",
    data: paras,
    type: "POST",
    proccessData: false, // this is true by default
    success: function(ret){callback(ret);}
});

Honestly, I thought this was automatic, but since your url is too long it's worth a shot.

Upvotes: 6

Related Questions