Reputation: 4555
$.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 get sent. I already tried this:
azione = escape(String(azione));
With no luck. Does anybody knows how to fix this?
Upvotes: 12
Views: 8458
Reputation: 31
escape(String(azione)).replace(new RegExp( "\\+", "g" ),"%2B");
this one sends the plus symbol with the help of regular expression
Upvotes: 2
Reputation: 51817
azione = escape(String(azione));
should be
azione = encodeURIComponent(String(azione));
or simply
azione = encodeURIComponent(azione);
Upvotes: 16
Reputation: 1039298
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.
Upvotes: 14
Reputation: 37813
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);}
});
Upvotes: 6