Home > Article > Web Front-end > Comparison of different examples of ajax and post processing json in jQuery_jquery
Recently, when I was making user comments on the portal, I hadn’t used jquery for a long time and I just happened to use it. I didn’t expect to cut corners and use the post method to process the json data of the ajax callback. I couldn’t get it, and there was json returned in the background. . Unexpectedly, such a small problem hung me up for several hours. Later, I handled it with the ajax method and it was OK. After a comparison, I found that the post method callback json must be eval, and the ajax method has been processed by default. Please be careful.
function haha() { jQuery.post("addComment!comment.action", function aa(data) { data = eval(data);//POST方法必加,ajax方法自动处理了 alert(data[0].userId); alert(data[0].userName); }, "json" ); jQuery.ajax({ type:"post", url:"addComment!comment.action", dataType:"json", success: function aa(data) { alert(data[0].userId); alert(data[0].userName); } }); }
Backstage:
Configuration: