最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to deal with response data in ajaxComplete event - Stack Overflow

programmeradmin2浏览0评论

Say I have this code:

function onComplete(event, request, settings)
{
    // How do I get the data? In the correct format?
}

$('body').ajaxComplete(onComplete);

In regular ajax success handlers, I can just access the data directly since it will be the first parameter to the handler. It will also be in the correct format (as long as the content-type was set right on the server).

How do I deal with the data on the ajaxComplete event?

Say I have this code:

function onComplete(event, request, settings)
{
    // How do I get the data? In the correct format?
}

$('body').ajaxComplete(onComplete);

In regular ajax success handlers, I can just access the data directly since it will be the first parameter to the handler. It will also be in the correct format (as long as the content-type was set right on the server).

How do I deal with the data on the ajaxComplete event?

Share edited Dec 20, 2015 at 18:58 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 30, 2010 at 11:43 SvishSvish 159k182 gold badges476 silver badges632 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

You can use it like this, but it's not documented:

function onComplete(event, request, settings) {
  var data = $.httpData(request, settings.dataType, settings);
}

The jQuery.httpData function is what's used internally to get data for the success handler, but you can use it directly. Please be aware that it is undocumented, and therefore subject to change without notice in new releases. For example in jQuery 1.4.3, it will be jQuery.ajax.httpData instead.

According to the the doc:

http://api.jquery./ajaxComplete/

I don't think you mean to fiddle with the data, because it doesn't pass any data to the handler. If you want data you better off using the set success property in regular Ajax.

This may not be the right handler to use if you want to get data as this is really intended more as a basic notification callback (for all hooked elements) when any AJAX calls pletes.

To get to your data you should you might need to be more targeted in your approach and use the $.ajax() call or one of its variants like $.get() or $.getJSON(). See here

发布评论

评论列表(0)

  1. 暂无评论