简体   繁体   中英

How to transform accented characters in html using Javascript?

I'm using a form to record data in my database using AJAX. So, how this works? I get the form data via Javascript, request a URL which is written in PHP then insert to the database.

The problem is that I'm using Latin 1 characters so the form is expecting also accented characters like ó . I need to convert this ó to html ( ó ) in javascript, so that I can pass it to PHP.

How doI do that?

This should do it for you:

function escapeHTMLEncode(str) {
  var div = document.createElement(‘div’);
  var text = document.createTextNode(str);
  div.appendChild(text);
  return div.innerHTML;
 }

http://sanzon.wordpress.com/2008/05/01/neat-little-html-encoding-trick-in-javascript/

我认为最好的方法是向PHP页面发出AJAX请求,输出htmlentities()的结果。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM