I have a simple simple form with a text box and a button, and my goal is for the asynchronous request (jQuery: $ .ajax) to send the text to the server (PHP / mysql a la Joomla) so that it can be added to the base table data.
Here's the javascript that sends data from the client:
var value= $('#myvalue').val(); $.ajax( { type: "POST", url: "/administrator/index.php", data: { option: "com_mycomponent", task: "enterValue", thevalue: value, format: "raw"}, dataType: "text", success: reportSavedValue } );
The problem occurs when the user enters text with a space in it. The $ _POST variable that I get has all the spaces, so if the user enters " This line has spaces ", the server gets the value " Thisstringhasspaces ".
I work in search engines and have found many links that I need to use encodeURIComponent. So I tried, but now the value I get from $ _POST is " This20string20has20spaces ".
Thus, he seems to encode it as I would expect, only to exclude percent signs instead of spaces and leave hexadecimal numbers.
I'm really confused. It seems that this kind of question is being asked and answered everywhere on the Internet, and everywhere encodeURIComponent is welcomed as a silver bullet. But apparently, Iām fighting another breed of lycanthrope. Anyone have any suggestions?
source share