Jquery ajax call with '+' sign

前端 未结 6 556
时光说笑
时光说笑 2021-01-02 02:41
$.ajax({  
        type: \"POST\", url: baseURL+\"sys/formTipi_azioni\",data:\"az_tipo=\"+azione,
        beforeSend: function(){$(\"#form\").html(\'

相关标签:
6条回答
  • 2021-01-02 02:59

    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.

    0 讨论(0)
  • 2021-01-02 03:04

    you are looking for encodeURIComponent

    0 讨论(0)
  • 2021-01-02 03:14
    azione = escape(String(azione));
    

    should be

    azione = encodeURIComponent(String(azione));
    

    or simply

    azione = encodeURIComponent(azione);
    
    0 讨论(0)
  • 2021-01-02 03:18
    escape(String(azione)).replace(new RegExp( "\\+", "g" ),"%2B");
    

    this one sends the plus symbol with the help of regular expression

    0 讨论(0)
  • 2021-01-02 03:20

    Never use escape(). Use encodeURIComponent().

    0 讨论(0)
  • 2021-01-02 03:20

    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);}  
     });
    
    0 讨论(0)
提交回复
热议问题