weixin_33690963 2010-06-30 09:09 采纳率: 0%
浏览 106

在页面上跟踪Ajax请求

I have a web page and I am associating a note with the page storing it in my database, so that the whenever the next time the page is loaded that notice can been seen till it is deleted by some other user authorized to do the same. However, say I associate a note with the page after some content is loaded through AJAX. I want the note to appear only after that particular content has loaded next time on the web page. I would like to track the AJAX request and attach the note to it? I want to do it all through simple JavaScript code put at the bottom of any web page. How can it be done?

  • 写回答

2条回答 默认 最新

  • weixin_33691598 2010-08-27 18:23
    关注

    You'd need to write a wrapper for all of your ajax calls that checks the result and sees if it should add a note. Here's an example, assuming you're using jQuery to handle the ajax requests:

    function ajaxWrapper(settings){
    
        var old_callback = settings.complete;
    
        settings.complete = function(request, status){
            if(status == "200"){
                // check the request.responseText and add your note if appropriate 
            }
    
            if(old_callback){
                old_callback(request, status);
            }
        }
    
        jQuery.ajax(settings);
    }
    

    And then instead of calling jQuery.ajax() directly, call ajaxWrapper() instead.

    An alternate option would be to include the note in your ajax response.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!