Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress GET Parameters in Javascript to avoid hitting the browser size limit?

I have gotten myself into a situation where I am required to make a JSONP Ajax GET request (cross domain) and I need to send a document > 2000 characters in length as a parameter.

For various reasons, I cannot change it from JSONP to a normal request and I cannot maintain state on server side to split the request into several.

Given these limitations, is there a way to compress the long text somehow in Javascript so I can fit it inside the 2000 GET limit size? I'd also need to know if I can easily decompress it on server side?

Because it is a GET request it can only be sent as a text so binary compression may not be possible?

like image 610
Ravish Bhagdev Avatar asked Apr 26 '12 14:04

Ravish Bhagdev


1 Answers

Switch to POST raw data and use JSON or XML for saving and sending big structures via a request.
If you use JQuery for example you have

jQuery.post( url, [data], [callback], [type] )

where data could be xmlDoc, jsonObj, html, text, etc...

instead of data you could have something like:

$.post("path/to/my/file.php", { func: "yourFunctionName" },
  function(data_returned_from_backend_json){
    //use data_returned_from_backend_json.properties
  }
, "json");

function yourFunctionName()
{
   //save all GET params into a json structure
}

source: http://docs.jquery.com/Post

like image 58
manyacy Avatar answered Nov 15 '22 00:11

manyacy