I've got a real simple form having a textbox along with a button, and let me come with an asynchronous request (jQuery: $.ajax) send the written text towards the server (PHP/mysql a la Joomla) to ensure that it may be put into a database table.

Here's the javascript that's delivering the information in the client:

var value= $('#myvalue').val()

$.ajax( Publish",

    url:        "/administrator/index.php",

    data:       ,

    dataType:   "text",

    success:    reportSavedValue


The issue arises once the user makes its way into text having a space inside it. The $_Publish variable which i receive has all of the spaces removed out, to ensure that when the user makes its way into "This string has spaces", the server will get the worthiness "Thisstringhasspaces".

I've been searching around, and also have found plenty of references that I have to use encodeURIComponent. And So I have attempted it, however the worthiness which i get from $_Publish is "This20string20has20spaces".

Therefore it seems to become encoding it the way in which I would expect, only to achieve the percent signs removed rather than the spaces, and departing the hex amounts.

I am really confused. It appears this kind of real question is requested and clarified everywhere on the internet, and everywhere encodeURIComponent is praised because the silver bullet. But apparently I am fighting another variety of lycanthrope. Does anybody have suggestions?

It works out that there is extra blocking I did not realize I had been carrying out. As this was all running through Joomla, I had been using JRequest::getCmd('thevalue') rather than $_Publish['theValue]. This function, it works out, filters out all individuals difficult figures, like '%'.

Therefore the final solution is by using encodeURIComponent around the client, out of the box all recommended on the internet:

var value = encodeURIComponent($('#myvalue').val())

As well as on the server, to trade getCmd() for getVar() which enables with additional control within the blocking, in conjunction with urldecode():

$value = urldecode(JRequest::getvar('thevalue', JREQUEST_ALLOWHTML))

Again, large because of Karim79 and Cesar. I dub thee Harker and Helsing -- my heroes during the day! :)

Could I trouble you to do this, please?

var value = escape($('#myvalue').val())