jQuery的阿贾克斯多个呼叫
我用下面的code有这样多的Ajax请求:
I'm using the following code to have multiple ajax requests like this:
要求 1开始 |要求 1完成 |要求 2开始 |要求 2完成 | ......
request 1 start | request 1 finish | request 2 start | request 2 finish | ...
这是在code:
var startingpoint = fireRequest(1);
$.each(types,function(ix,type)
{
startingpoint = startingpoint.pipe( function()
{
alert(startingpoint.status); // undefined
return fireRequest(type);
});
});
fireRequest 只是一个switchcase正确的ajax函数返回$阿贾克斯(...)
fireRequest is just a switchcase to the correct ajax function which returns $.ajax(...)
我想链条,当一个请求无法停止。我开始实施,并作为一个测试,我想提醒AJAX对象的状态,但它显示未定义。我怎样才能得到的地位?
I'd like the chain to stop when one request fails. I started implementing it and as a test I'd like to alert the status of the ajax object, but it shows 'undefined'. How can I get the status?
正在试图执行的行为已经是.pipe()方法的行为。它需要两个回调作为参数,只会执行完成回调,并沿着供应链继续,如果previous请求成功。这可说明在下面的jsfiddle: http://jsfiddle.net/dflor003/Vq2YF/ (注:在具有浏览器中打开该内置JSON.stringify支持和执行console.log支持)
The behavior you are trying to implement is already the behavior of the .pipe() method. It takes two callbacks as parameters and will ONLY execute the done callback and continue along the chain if the previous request succeeds. This can be illustrated in the following jsfiddle: http://jsfiddle.net/dflor003/Vq2YF/ (Note: open this in a browser that has built-in JSON.stringify support and console.log support)
如果你想检查请求的状态,将采取的状态作为第二个参数进行回调。更多详细信息可以在jQuery的API文档网站上找到: http://api.jquery.com/deferred.pipe /
If you do want to check the status of a request, it will take the status as the second parameter to the done callback. More detail can be found on jQuery's API documentation site: http://api.jquery.com/deferred.pipe/