jquery - how to escape html to prevent XSS?

前端 未结 3 611
清酒与你
清酒与你 2021-01-15 02:35

I\'m using laravel, when a user sends a text message, it may contain some malicious code. When I use {{}} it will show me the exact text the user has sent. If h

3条回答
  •  悲&欢浪女
    2021-01-15 02:48

    You should use jQuery text() to encode the data.

    $('#mydata').text(data);
    

    EDIT: To create the content of #mydata you can use

    $('#mydata')
      .html("")
      .append($("

    ").text(response.name)) .append($("

    ").text(response.description))

提交回复
热议问题