I am currently working on developing an android application that involves sending data to the server side using GPRS and SMS (via an SMS gateway). The challenge I am facing is with formatting the data before sending it to the SMS gateway. The format provided includes white spaces between the data elements. However, when these white spaces are URL encoded, they appear as "+" symbols. I would prefer to encode the space as "%20" instead of "+", as URLs do not fully support the use of "+". How can I achieve this? Your help is greatly appreciated. Thank you in advance.
Here is the source code:
function AttForm()
{
var att=$('#attnce').val();
var uname=window.localStorage.getItem('uname');
if(att==0){
alert("Select Attendance");
return false;
}
var message="MRCC";
message += " "+"VIPATT";
message += " "+uname;
message += " "+att;
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';
if(states[networkState]==states[Connection.NONE]){
window.plugins.sms.send(09192939495,message,function(){
alert('Message sent successfully');
},
function (e) {
alert(e);
});
}
else{
$.ajax({
url:'http://aaa.com/test/webservice.php',
type:'POST',
data:{type:'VIPATT',message:message},
dataType:'jsonp',
jsonp:'callback',
success:successData,
error:function(){
alert("error")
}
});
function successData(data){
var response=data.message;
alert(response);
$('#att').hide();
$('#main_menu').delay(500).fadeIn(1000)
}
}
}
The URL generated looks like this:
http://aaa.com/test/webservice.php?callback=jQuery16006898061116226017_1343803442450&type=VIPATT&message=MRCC+VIPATT+RSA+2&_=1343803455743:1
In the above URL, you can notice the presence of the "+" symbol between the attributes. However, I aim to replace the "+" with "%20". Any suggestions on how to achieve this?