Escaping ampersand in URL

前端 未结 8 1311
余生分开走
余生分开走 2020-11-22 03:25

I am trying to send a GET message that contains strings with ampersands and can\'t figure how to escape the ampersand in the URL.

Example:

http://www         


        
相关标签:
8条回答
  • 2020-11-22 03:42

    This may help if someone want it in PHP

    $variable ="candy_name=M&M";
    $variable = str_replace("&", "%26", $variable);
    
    0 讨论(0)
  • 2020-11-22 03:51

    You can rather pass your arguments using this encodeURIComponent function so you don't have to worry about passing any special characters.

    data: "param1=getAccNos&param2="+encodeURIComponent('Dolce & Gabbana') OR
    var someValue = 'Dolce & Gabbana';
    data : "param1=getAccNos&param2="+encodeURIComponent(someValue)
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

    0 讨论(0)
提交回复
热议问题