0

I'm creating a web using nodejs, ExpressJS, EJS and MySQL. I save some data with HTML code in MySQL. When I get data from MySQL and show in web,an error occur: HTML tag in data also showing with data. How can you help me solve this problem. Thanks.

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
Huệ Phan
  • 11
  • 2

1 Answers1

0

Try to pass your output through a function such as:

function escapeHtml(unsafe) {
    return unsafe
         .replace(/&/g, "&")
         .replace(/</g, "&lt;")
         .replace(/>/g, "&gt;")
         .replace(/"/g, "&quot;")
         .replace(/'/g, "&#039;");
 }

Shamelessly copied from here.

Community
  • 1
  • 1
cgf
  • 3,369
  • 7
  • 45
  • 65