简体   繁体   English

如何调试jQuery POST AJAX操作?

[英]How to debug a jQuery POST AJAX operation?

I want the data coming from the server to show in the <div id="demo"> element. 我希望来自服务器的数据显示在<div id="demo">元素中。

But sometimes, it just appears and goes, and other times, it is not even showing up. 但有时候,它只会出现和消失,有时甚至不会出现。 I searched and tried lots of options, but nothing works for me. 我搜索并尝试了很多选项,但没有什么对我有用。

My code is: 我的代码是:

 function loadDoc(){     
   document.getElementById("demo").innerHTML = "Paragraph changed!";
   alert("hello world");
   $.ajax({
     type:'POST',
     url :"new_mark.php",
     data :"regno=u4cse13xxx",
     success: function(data) {          
        //$("demo").html = "Narayana!";
        document.getElementById("demo").innerHTML = data;
        alert(data);
     }
   });
 }

To debug an web site, i advise you tu use the Chrome debugger or on generaly the browser debugger its very simple and usefull. 为了调试网站,我建议您使用Chrome调试器,或者通常使用浏览器调试器,它非常简单和有用。

Click F12 and go to ressources and put an debug point at your line and it finished 单击F12并转到ressources并将调试点放在您的行上并完成

Just call the Element and set the the content via a jquery method like text (Reference: .text() ) 只需调用Element并通过类似文本的jquery方法设置内容(参考: .text()

So your code inside success would be: 所以你成功的代码将是:

success: function(data) {          
    $("#demo").text(data);
 }

And maybe you can tell me if it worked? 也许你可以告诉我它是否有效? :) Greets! :)问候!

Go to the Network tab of the debugger, select your request (new_mark.php), then check the Response tab. 转到调试器的“网络”选项卡,选择您的请求(new_mark.php),然后选中“响应”选项卡。 If there was an error, it should appear in the response. 如果出现错误,它应该出现在响应中。

For example in Chrome: 例如在Chrome中:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM