views:

256

answers:

1

I am trying to save Mobile Number in MYSQL table with following Format "+1234987...."

but when i save data + sign is replaced with space, i am using 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 try both with escape() and also with out escape, same result.

how can i make it to save with + sign

Thanks

+1  A: 

"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)
bobince