admin管理员组

文章数量:1323714

I have a problem with printing Ajax success data.

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

How it es 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

I have a problem with printing Ajax success data.

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

How it es 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

Share Improve this question edited Nov 8, 2013 at 18:35 웃웃웃웃웃 12k15 gold badges62 silver badges94 bronze badges asked Nov 8, 2013 at 18:20 Plic PlPlic Pl 5513 gold badges7 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

alert data

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

write to div tag

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

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

Say you have a div to print the result like

<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

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

Just drill down the data object to the errors.text array and loop through them, like this:

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

本文标签: javaPrint AJAX Success DataStack Overflow