Search code examples
javascriptjqueryhtmlajax

HTTP Error 414. The request URL is too long


I am using ckeditor to format some data inside my textarea

<textarea id="editorAbout" rows="70" cols="80" name="editorAbout"></textarea>

Now when i try to post this data using jQuery.ajax like this,

var about=escape( $("#editorAbout").text());
            $.ajax({
             type: "POST",
             url: "../Allcammand.aspx?cmd=EditAboutCompany&about="+about,
             type:"post",
                async: false ,
                   success: function(response){                                       

                    },
                    error:function(xhr, ajaxOptions, thrownError){alert(xhr.responseText); }
            });

I get the error

HTTP Error 414. The request URL is too long.

I am getting the error here: http://iranfairco.com/example/errorLongUrl.aspx
Try clicking on the Edit Text button at the bottom left of that page.

Why is this happening? How can I solve it?


Solution

  • According to this question the maximum practical length of a URL is 2000 characters. This isn't going to be able to hold a massive Wikipedia article like you're trying to send.

    Instead of putting the data on the URL you should be putting it in the body of a POST request. You need to add a data value to the object you're passing to the ajax function call. Like this:

    function editAbout(){
    
        var about=escape( $("#editorAbout").text());
        $.ajax({
            url: "Allcammand.aspx?cmd=EditAboutCompany&idCompany="+getParam("idCompany"),
            type:"post",
            async: false,
            data: {
                about: about
            },
            success: function(response){                                       
            },
            error:function(xhr, ajaxOptions, thrownError){alert(xhr.responseText); ShowMessage("??? ?? ?????? ??????? ????","fail");}
        });
    }