I wasnt quite sure how to ask this question, sorry.. but basically it’s this..
I just started out w/ Ajax .. and with sending XMLhttpRequest in the background, i’m having problems w/ some html special characters in the form data , specially the & sign terminating the variable prematurely
eg. value “You & I” results to “You ”
Now to explain this question from my perspective.. it’s simply this.. if i submit my regular form using GET method, the same thing happens.. since the variables are URL-Encoded.. but if i set the form to POST method then everything is PRESERVED as i needed it..
Now I believe it has something to do w/ this (?)
hr.open("POST", link, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
particularly on the form-urlencoded part.. is there an alternative?
i’d hate to have to run a cleanup routine on each variable that i pass thru Ajax 🙁
&is supposed to terminate values in x-www-form-urlencoded data. You need to encode your data when building URLs.No. If you submit a regular form using GET, then the inputed data will be URL Encoded and ampersand characters that appear as data will be represented by
%26and not as raw&characters so the same thing won’t happen.You can use any data format you like. Some are easier to generate than others (JSON is particularly easy to generate from a browser). You then have the challenge of decoding them on the server (form handling libraries don’t tend to do JSON, so you’d have to get the raw POST data and decode it yourself).
Since your actual problem is solved by encoding your data, this is unnecessary.