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 06:47 PM.
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.
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 ?
You can use a form with the POST method and an text or hidden type input.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)