1

I'm passing data on a page1 through a querystring onto page2, when a user clicks the button "send" the data is passed on the querystring and page2 gets the 'data=..' parameter from the querystring and shows it's value on the page.

The problem is that the data on page1 is created through the user by the input textbox and can be quite long. This gives us the following error when the user clicks "send"

URL Requested is too long

This is the code used to get the span element(submitted text by user) and convert it to a variable which is added onto the querylink:

$('#send').click(function() {
    var data_text = $('span').prop('outerHTML');
    window.location.href = 'http://swter.com/send.php?data=' + data_text + '';
    return false;
});

Are there anyways around it apart from limiting the amount of chars a user can type?

  • Why are you sending all that data through the url? – KingAlfredChameleon Jan 18 '15 at 14:02
  • Because I'm using Tornado webserver and it doesn't support the POST method so querystring is the only way to send data onto another page. – StackOverQuestions Jan 18 '15 at 14:03
  • 1
    `querystring` can't be longer than `255` characters and you can't by pass this by any means .. POST method is the only way to go .. – Syed Qarib Jan 18 '15 at 14:04
  • Do you really need to send all the HTML data. That's a lot of overhead. Can't you chop it up in pieces and send them over as JSON and reconstruct on the other page? – Mouser Jan 18 '15 at 14:06
  • 1
    How do I chop the data into pieces and send with JSON? – StackOverQuestions Jan 18 '15 at 14:11
  • After a long extensive search on proper POST method in Tornado, I failed to find any methods, but i suggest making a post method in js and sending variable with it. See here; http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit?rq=1 Mouser's suggestion isn't feasible. – KingAlfredChameleon Jan 18 '15 at 14:27
  • If they do not support post, you picked the wrong tool for the job. – epascarello Jan 18 '15 at 14:45
  • Tornado definitely does support POST, so maybe you should post another question with your server-side code to figure out why that's not working for you. – Ben Darnell Jan 18 '15 at 16:05
  • Hey Ben; here's a question containing code which is exact to mine http://stackoverflow.com/questions/27951644/tornado-post-method-not-found I've tried replacing "get" with post but to no avail. – StackOverQuestions Jan 18 '15 at 17:06

1 Answers1

1

So you could split the contents of the textarea into multiple strings using String#split and then loop through the resulting array and make AJAX GET requests to your back end server. You will need to include a form of unique identifier that ties each batch of data together on the server, and an index so you can rebuild it, ie:

?id={{unique_id}}&page=1&total=6&body={{message_page_1_of_6}}

However, as pointed out, a POST request would be more appropriate here.

JonnyReeves
  • 5,919
  • 1
  • 23
  • 28