当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 一周乱弹(1,jsif(!param)判断,2,jquery$.when().then())

一周乱弹(1,jsif(!param)判断,2,jquery$.when().then())

2019年06月19日  | 移动技术网IT编程  | 我要评论

1,在js的if判断里以下几种情况默认为false
null
undifined

0 (数字0)

所以在if判断中加上!就为true 。
2,jquery

$.when($.ajax("/page1.php"), $.ajax("/page2.php"))
  .then(myfunc, myfailure);

e.g:

  $.when(
                        //转介原因
                        $.get("mvc/alarm/get-value/turn_reason_type"+"?"+math.random(),null,"json"),
                        //后续处置科室负责人
                        $.get("mvc/alarm/alarm_dept_all"+"?"+math.random(),null,"json"),
                        //案件影响程度
                        $.get("mvc/alarm/get-value/crime_urgent_type"+"?"+math.random(),null,"json")
                    ).then(function(data1, data2,data3) { // 成功回调,所有请求正确返回时被调用

                        var d1 =data1[0].data;
                        if(null != d1) {

                            $("#referralreason option:not(:first)").remove();
                            var options = $("#referralreason");
                            //拼接
                            $.each(d1, function (index, item) {
                                options.append($("
<option>&quot;).val(item.id).text(item.keyvalue)); }); } var d2=data2[0].data; if(null != d2) { $(&quot;#afterman option:not(:first)&quot;).remove(); var options = $(&quot;#afterman&quot;); //拼接 $.each(d2, function (index, item) { options.append($(&quot;</option><option>&quot;).val(item.id).text(item.alertuser.realname)); }); } var d3=data3[0].data; if(null != d3) { $(&quot;#urgency_e option:not(:first)&quot;).remove(); var options = $(&quot;#urgency_e&quot;); //拼接 $.each(d3, function (index, item) { options.append($(&quot;</option><option>&quot;).val(item.id).text(item.keyvalue)); }); } }, function() { // 错误回调,任意一个请求失败后将被立即执行 alert( &#39;数据不完整,请联系管理员!&#39; ); });</option>

其中直接在when的ajax方法里处理回调也是可以的:

 $.when(
                        //转介原因
                        $.get("mvc/alarm/get-value/turn_reason_type"+"?"+math.random(),function (resp) {
                            //***在when的ajax方法里处理回调也是可以的***

                        },"json"),
                        //后续处置科室负责人
                        $.get("mvc/alarm/alarm_dept_all"+"?"+math.random(),null,"json"),
                        //案件影响程度
                        $.get("mvc/alarm/get-value/crime_urgent_type"+"?"+math.random(),null,"json")
                    ).then(function(data1, data2,data3) { // 成功回调,所有请求正确返回时被调用

                        var d1 =data1[0].data;
                        if(null != d1) {

                            $("#referralreason option:not(:first)").remove();
                            var options = $("#referralreason");
                            //拼接
                            $.each(d1, function (index, item) {
                                options.append($("

 

<option>&quot;).val(item.id).text(item.keyvalue)); }); } var d2=data2[0].data; if(null != d2) { $(&quot;#afterman option:not(:first)&quot;).remove(); var options = $(&quot;#afterman&quot;); //拼接 $.each(d2, function (index, item) { options.append($(&quot;</option><option>&quot;).val(item.id).text(item.alertuser.realname)); }); } var d3=data3[0].data; if(null != d3) { $(&quot;#urgency_e option:not(:first)&quot;).remove(); var options = $(&quot;#urgency_e&quot;); //拼接 $.each(d3, function (index, item) { options.append($(&quot;</option><option>&quot;).val(item.id).text(item.keyvalue)); }); } }, function() { // 错误回调,任意一个请求失败后将被立即执行 alert( &#39;数据不完整,请联系管理员!&#39; ); });</option>

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网