4

Is there a limit to the length of the parameter that be can added to the url for ajax? I am using Thin server on Ruby, and did an ajax request from the web browser in this format:

io=new XMLHttpRequest();
io.open("GET","http://localhost:3000&v="+encodeURIComponent(JSON.stringify(v)),true);

When the length of the string v exceeds about 7000 bytes, it seems to crash. When less, it seems to work. Is my observation right? Where is the restriction coming from? From Thin, Javascript, or the browser? I use Google Chrome browser.

sawa
  • 165,429
  • 45
  • 277
  • 381
  • possible duplicate of [Max length of query string in an AJAX GET request?](http://stackoverflow.com/questions/1344616/max-length-of-query-string-in-an-ajax-get-request) – Colin Brock Mar 23 '12 at 15:14

3 Answers3

8

Is there a limit to the length of the parameter that can added to the url for ajax?

Yes, if you are using a GET request there's a limit which will depend on the client browser. And this limit has nothing to do with AJAX. IIRC it was around 4K for IE but things might have changed. But in any case there's a limit. If you don't want to be limited you should use POST.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • If I use different request types, will the limit get longer? – sawa Mar 23 '12 at 15:14
  • @sawa, no. The limit depends on the browser you are using. – Darin Dimitrov Mar 23 '12 at 15:14
  • This question is about ajax requests that hit a server... there is no browser that is loading this url... its an ajax request that is sent FROM a browser to a server. I don't believe there is a limit... the limit is something that is enforced by browsers... so..its true that loading that url in a browser would potentially not work... but the server should not care. – Nawlbergs May 24 '19 at 14:19
1

Restriction most likely comes from the browser. According to this discussion you should try to keep your URLs under about 2000 characters.

Community
  • 1
  • 1
socha23
  • 10,171
  • 2
  • 28
  • 25
-3

There is a limit to the GET request depending on the character bytes. If you use ASCII it's 256 characters including the url itself. For UTF-8 it's practically the half because 1 utf character is 2bytes long.

You won't have this problem on POST though.

Panagiotis
  • 1,539
  • 1
  • 14
  • 28