Reputation: 6264
I am trying to save a mobile number in MYSQL table with the following format "+1234987...." but when I save the number the '+' sign is replaced with a space.
I am using the following code:
var mobile = $('#mobile').attr('value');
$.ajax({
type: "POST",
url: "save_process.php",
data: "mobile="+ escape(mobile) ,
//data: "mobile="+ mobile ,
success: function(html){
if (html==1){
$('div.saving').hide();
$('div.success').fadeIn();
}
I tried both with and without escape()
-- same result. How can I make it save with the '+' sign?
Thanks
Upvotes: 0
Views: 824
Reputation: 536429
"mobile="+ escape(mobile)
escape
is the wrong function to use for encoding URI parameters. It is a special JavaScript-only encoding scheme that looks a bit like URL-encoding, but isn't that or indeed any other web standard. It differs in handling of non-ASCII characters and, you guessed it, the plus sign.
In fact it is almost always the wrong function to use for anything and you should be immediately suspicious any time you see it. It used to be used for URL-encoding back in the Netscape days, before encodeURIComponent
was invented, but even for then it was completely broken.
"mobile="+ encodeURIComponent(mobile)
Upvotes: 2