我在打印 Ajax 成功数据时遇到问题。
success: function(data){
alert(need to print it here);
}
当我访问时它是如何出现的
console.log(data.responseText);
{"success":false,"errors":{"text":["Some text.","some more text"]}}
我现在如何提醒“一些文本”或“更多文本”?谢谢
我在打印 Ajax 成功数据时遇到问题。
success: function(data){
alert(need to print it here);
}
当我访问时它是如何出现的
console.log(data.responseText);
{"success":false,"errors":{"text":["Some text.","some more text"]}}
我现在如何提醒“一些文本”或“更多文本”?谢谢
警报数据
success: function(data){
alert(data);
}
写入 div 标签
<div id="mydiv"></div>
success: function(data){
document.getElementById("mydiv").innerHTML += data;
}
只需将data
对象向下钻取到errors.text
数组并循环遍历它们,如下所示:
$.each(data.responseText.errors.text, function(index, item) {
alert(item);
});
假设您有一个 div 来打印结果,例如
<div id="res_div"></div>
您可以通过以下方式访问内容
console.log(data.responseText.errors.text);
您只需尝试以下操作即可将内容打印到该 div
$("#res_div").text(data.responseText.errors.text);