Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 get sent. I already tried this:

azione = escape(String(azione));

With no luck. Does anybody knows how to fix this?

like image 853
0plus1 Avatar asked Jun 11 '10 12:06

0plus1


2 Answers

azione = escape(String(azione));

should be

azione = encodeURIComponent(String(azione));

or simply

azione = encodeURIComponent(azione);
like image 86
oezi Avatar answered Nov 15 '22 14:11

oezi


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.

like image 24
Darin Dimitrov Avatar answered Nov 15 '22 13:11

Darin Dimitrov