0

The below codes get html, encode and send it to any php files. php files include just "hello" string. but when function runs it can get all html but cant send cause of string's long. Because you cant see the HELLO alert. Ajax allows defined longest? Am I right?

function getlongdata(){
    htmldatas=encodeURIComponent($('#divlongcontent').html());
    alert(htmldatas);
    $.ajax({
         type: "GET",
         url: "sayhello.php",
         data: "longdatago="+htmldatas,
         success: function(msg){
            alert(msg);
         }
     });
}


<div id="divlongcontent">blablabla1000000000timesblaaaaaaa</div>
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
zapata
  • 61
  • 10

3 Answers3

4

Browsers impose a limit on URL length.

If you are submitting a lot of data, use a POST request and put it in the message body instead of a query string.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Use POST instead of GET, according to Wikipedia:

There are times when HTTP GET is less suitable even for data retrieval. An example of this is when a great deal of data would need to be specified in the URL. Browsers and web servers can have limits on the length of the URL that they will handle without truncation or error. Percent-encoding of reserved characters in URLs and query strings can significantly increase their length, and while Apache HTTP Server can handle up to 4,000 characters in a URL, Microsoft Internet Explorer is limited to 2048 characters in any URL. Equally, HTTP GET should not be used where sensitive information, such as user names and passwords have to be submitted along with other data for the request to complete. In these cases, even if HTTPS is used to encrypt the message body, data in the URL will be passed in clear text and many servers, proxies, and browsers will log the full URL in a way where it might be visible to third parties. In these cases, HTTP POST should be used.

DarkAjax
  • 15,955
  • 11
  • 53
  • 65
0

As long as your data is less than 2000 characters, you can safely use get. But, if at some point you feel that it is going over that limit, it will not work consistently in all browsers.

In your ajax call, change the type from get to post and everything should work fine.

There is no limit to how much data you can send using post

Abhilash
  • 1,610
  • 9
  • 19