None
None

Reputation: 5670

Ajax POST does not works

I am sending my entire page html back to server using jquery ajax post My code is like this

    $(document).ready(function () {

    var pcontent = document.body.innerHTML;

    var url = new URI().addQuery("pcontent", pcontent);

    $.ajax({
        url: url, type: "POST"
      , success: function (data) {

          alert(data.html());
      },
        complete: function () {
            alert(1);
        },
        error: function (jqXHR, error, errorThrown) {
            if (jqXHR.status) {
                alert(jqXHR.responseText);
            } else {
                alert("Something went wrong");
            }
        }
    });
    return false;
});

but the code makes an error like this

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

<HTML><HEAD><TITLE>Request URL Too Long</TITLE>

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>

<BODY><h2>Request URL Too Long</h2>

<hr><p>HTTP Error 414. The request URL is too long.</p>

</BODY></HTML>

as far as i understood i cant send entire page html through an ajax post.Is it true? or is there any thing else that makes this error for me?

Upvotes: 0

Views: 1130

Answers (2)

Rohit Patel
Rohit Patel

Reputation: 459

The are limitation on number of characters in the URL. You can have max 2000 characters in your URL. Don't send your html in URL, instead use "data" parameter of jquery ajax. Something like

$.ajax({
        url: url, type: "POST", data: {pcontent: $(pcontent).serialize()}

Upvotes: 4

Raja Asthana
Raja Asthana

Reputation: 2100

Microsoft describes HTTP Error 414 like this:

The server is refusing to service the request because the Request-URI is too long. This rare condition is likely to occur in the following situations:

A client has improperly converted a POST request to a GET request with long query information.

A client has encountered a redirection problem (for example, a redirected URL prefix that points to a suffix of itself).

The server is under attack by a client attempting to exploit security holes present in some servers that use fixed-length buffers to read or manipulate the Request-URI. IIS checks the string length of the URI and does not service a request when the URI is longer than expected

From your query, you are sending the whole innerHtml as URL. That could be one of the reason. Use data instead.

Upvotes: 2

Related Questions