Java 打印 AJAX 成功数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19865887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:51:27  来源:igfitidea点击:

Print AJAX Success Data?

javajavascriptphpjqueryajax

提问by Plic Pl

I have a problem with printing Ajax success data.

我在打印 Ajax 成功数据时遇到问题。

success: function(data){
    alert(need to print it here);
}

How it comes when I access

当我访问时它是如何发生的

console.log(data.responseText);
{"success":false,"errors":{"text":["Some text.","some more text"]}}

How can I alert "Some text" or "some more text" now? Thanks

我现在如何提醒“一些文字”或“更多文字”?谢谢

回答by Deepu

Say you have a div to print the result like

假设你有一个 div 来打印结果

<div id="res_div"></div>

You can access the contents by

您可以通过以下方式访问内容

console.log(data.responseText.errors.text);

You just try the following to print the content to that div

您只需尝试以下操作将内容打印到该 div

$("#res_div").text(data.responseText.errors.text);

回答by Karl Anderson

Just drill down the dataobject to the errors.textarray and loop through them, like this:

只需将data对象向下钻取到errors.text数组并循环遍历它们,如下所示:

$.each(data.responseText.errors.text, function(index, item) {
    alert(item);   
});

回答by user2511140

alert data

警报数据

 success: function(data){
        alert(data);
    }

write to div tag

写入 div 标签

<div id="mydiv"></div>

success: function(data){
        document.getElementById("mydiv").innerHTML += data; 
    }