How to escape “&” ampersand character in form input using jQuery

后端 未结 5 1083
余生分开走
余生分开走 2020-12-30 06:00

I have a problem with my jQuery script that send data via POST method. The problem is whenever it sends data via Ajax that has an "&" ampersand in the sentence

5条回答
  •  无人及你
    2020-12-30 06:33

    htmlentites

    This function is identical to htmlspecialchars() in all ways, except with htmlentites(), all characters which have HTML character entity equivalents are translated into these entities.

    If you're wanting to decode instead (the reverse) you can use html_entity_decode().

    Example:

    echo htmlentities("&"); // &
    

    if your directly doing this in the browser you should be able to use:

    encodeURIComponent(string input);
    

    Example:

    encodeURIComponent($.trim($("input[name=t-tim_rendered-"+id+"]").val().toString()));
    

提交回复
热议问题