从json返回的数据中的html标签 [英] html tags in data returned from json
问题描述
我有一个php页面,它在json中返回一些数据.基本上我在此页面上做回声.
I have a php page that is returning some data in json. Basically I am doing echo on this page.
返回的数据具有一些html标记.这导致我的jQuery代码中断.
The data being returned has some html tags. This is causing my jQuery code to break.
有没有办法在将数据放入json对象之前清理数据并剥离标签?
Is there a way to clean up the data and strip off the tags before putting it in the json object?
此外,我正在尝试将json中的数据显示到文本区域中,理想情况下,我想在文本区域中显示html标签...
Furthermore, I am trying to display the data from json into a textarea and ideally I would like to show the html tags in the textarea...
推荐答案
When you create the json, you can use json_encode() on the values that have html in your php code - this will escape the values in json so that it validates and will be usable in jquery. I haven't tried it, but you should not have a problem adding the value to a textarea.
这篇关于从json返回的数据中的html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!