Вопрос

Hi I dont know why + sign is removed and how to eliminate it's removing.

Sample code is presented:

var customer_number = $('cust_num');
var l_sParams = 'number='+customer_number.value;
alert(l_sParams);

var l_sURL = '/caller/send_sms';   

new Ajax.Request(l_sURL, {parameters: l_sParams, method: 'POST', 
        onComplete:function(a_oRequest){    

    }.bind(this)
});

the alert displays ex: +1907727500

and if I print in Python it is printed without + sign like this ex:

_to_customer = self.request.post['number']

result: 1907727500 (without + )

Thank you

Это было полезно?

Решение

+ in a query parameter is the escape code for a space. You receive ' 1907727500', with the space.

Use %2B instead, or better still, have JavaScript quote your values properly

var l_sParams = 'number=' + encodeURIComponent(customer_number.value);

Другие советы

Strings containing a plus sign (or such special chars) should be urlencoded since it represents space in URLs. Use encodeURI() to do that.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top