Jquery ajax call with '+' sign
$.ajax({
type: "POST", url: baseURL+"sys/formTipi_azioni",data:"az_tipo="+azione,
beforeSend: function(){$("#form").html('<p><img src="'+baseURL+'lib/img/ajax-loader.gif" width="16" height="16" alt="loading" /><p>');},
success: function(html){$("#form").html(html);}
});
there is a case when azione is
TB+
the plus sign doesn't get POSTed at all, a blank space 开发者_StackOverflowget sent. I already tried this:
azione = escape(String(azione));
With no luck. Does anybody knows how to fix this?
azione = escape(String(azione));
should be
azione = encodeURIComponent(String(azione));
or simply
azione = encodeURIComponent(azione);
Try this:
$.ajax({
type: "POST",
url: baseURL + "sys/formTipi_azioni",
data: { az_tipo: azione },
beforeSend: function(){
$("#form").html('<p><img src="'+baseURL+'lib/img/ajax-loader.gif" width="16" height="16" alt="loading" /><p>');
},
success: function(html){
$("#form").html(html);
}
});
and leave jQuery do the url encoding for you.
Never use escape()
. Use encodeURIComponent()
.
Instead of trying to compose the post data yourself, you can also let jQuery do the work by passing it an object:
$.ajax({
type: "POST", url: baseURL+"sys/formTipi_azioni",
data: {az_tipo: azione},
beforeSend: function(){$("#form").html('<p><img src="'+baseURL+'lib/img/ajax-loader.gif" width="16" height="16" alt="loading" /><p>');},
success: function(html){$("#form").html(html);}
});
you are looking for encodeURIComponent
escape(String(azione)).replace(new RegExp( "\\+", "g" ),"%2B");
this one sends the plus symbol with the help of regular expression
精彩评论