Results 1 to 5 of 5

Thread: Sending large amounts of text to PHP via GET

  1. #1
    Join Date
    Jun 2010

    Sending large amounts of text to PHP via GET

    Hey guys! So I have kind of a weird question:

    I've written some code that uses XMLHttpRequest(); to get data from a page on my server. It stores the response text in a variable, like so: resp=x.responseText;

    I can use "alert(resp);" to view the text and I know it's working correctly.

    My question is this: I want to then send this response text to another .php page, kind of like this: "http://www.example.com/test.php?c="+resp

    However, because the response text has HTML code in it, as well as line breaks (\n) and other weird stuff, my test.php file isn't getting the data correctly. Do I have to like santize the "resp" string using some kind of HTML character conversion code or something? Do you have any suggestions?

    Similar/related question: is there a way to just cut the "resp" content to the first like 200 characters? It responds with a ton of crap, which I really don't need beyond the first 200-300 characters or so.
    Last edited by icydash; 09-15-2012 at 07:47 PM.

  2. #2
    Join Date
    Mar 2011
    You should use urlencode() on all such strings before using them in a query string, and you could use substr() to adjust the length. But you could avoid all the hassle by just using POST instead of GET.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jun 2010
    Thanks for your response.

    Is it just urlencode(str)? I also did some search and noticed there is encodeURIComponent() and encodeURI(). What are the differences between these three?

    How can I use POST instead of GET if I'd be sending the user to the website "http://www.example.com/test.php?c="+resp ?

  4. #4
    Join Date
    Oct 2010
    Versailles, France
    With javascript the GET form is http://www.example.com/test.php?c="+encodeURIcomponent(rsp), to use without urldecode (See this page) . But «The get method is not suitable for very large variable values. It should not be used with values exceeding 2000 characters.» (See W3cscholls.com).

    You can use a form with the POST method and an text or hidden type input.

  5. #5
    Join Date
    Mar 2009
    is it really a requirement to involve javascript or client side scripting. if you only want to send out put to some different php script you can do it directly.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center