weixin_33711647 2014-12-22 07:49 采纳率: 0%
浏览 60

返回false继续执行

I have made 4 ajax calls, it should return false (stop), when record 123456 is found. Also, record 123456 might exist in all four ajax results. However, instead of stop, the code continues to execute.

var endPoint0 = '';
var endPoint1 = '';
var endPoint2 = '';
var endPoint3 = '';

$.when(
    $.ajax(endPoint0),
    $.ajax(endPoint1),
    $.ajax(endPoint2),
    $.ajax(endPoint3)
).then(pass);

function pass(a, b, c, d){
    var array = [];
    array.push(a[0].guides, b[0].guides, c[0].guides, d[0].guides);
    $.each(array, function(index,jsonObject){
        $.each(jsonObject, function(i, item){
            var e = item.program_id;
            if (e == 123456) {
                listing(item);
                return false;
            } else {
                console.log('no record');
            }
        });
    });
}

function listing () {
    // display output here
}
  • 写回答

3条回答 默认 最新

  • weixin_33694172 2014-12-22 08:12
    关注

    As Per Jquery Documentation http://api.jquery.com/jquery.when/

    var d1 = new $.Deferred();
    var d2 = new $.Deferred();
    
    $.when( d1, d2 ).done(function ( v1, v2 ) {
        console.log( v1 ); // "Fish"
        console.log( v2 ); // "Pizza"
    });
    
    d1.resolve( "Fish" );
    d2.resolve( "Pizza" );
    

    You need to mark callback as resolve. My Idea is to put your logic then and Mark it resolve and make the execution stops.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容