我正在尝试从 jQuery 访问 JSON 结果。
$.ajax({
type: "GET",
url: "http://localhost:8080/App/QueryString.jsp?Query="+query,
contentType:"text/html; charset=utf-8",
dataType: "json",
success: function(json) {
if(data!=""){
console.log(json);
var data = json.Json;
console.log(data);
}
}
});
但这给了我带有 HTML 标签的结果。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body> JSON:[Includes the result]</body>
</html>
我得到 json 输出,但包含 HTML 标签。我只想删除它们并仅获取 json 结果。
有人可以帮我解决这个问题吗? 和dataType和contentType有关系吗?
最佳答案
您使用:
contentType:"text/html; charset=utf-8"
这要求 HTML 格式。将其更改为:
contentType:"application/json; charset=utf-8"
您应该得到原始 JSON。
关于javascript - 删除 JSON 结果中的 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47010300/