JQ 实现Promise,ajax Promise-then-当一个函数返回结果在往下执行

ajax1(number).then(function (appNumData) {
	console.log(appNumData);//ajax1请求返回后的值
	ajax2(appNumData);//执行
};
function ajax1(data1) {
    var def= $.Deferred();//1.定义
    var url = window.location.origin +'';
    $.ajax({
      url: url,
      type: "GET",
      beforeSend: function (XMLHttpRequest) {
        // $('.loading-box').show();
      },
      data: {
        'standardNumber': $standardNumber
      },
      dataType: "json",
      success: function (dataList) {
        // console.log(data);
        if (dataList.status == 'STATUS_SUCCESS') {
          var data = dataList.content.content;
          def.resolve(dataList);//2.
          def.promise(dataList);//3.
        }
      },
      complete: function () {
      }
    });
    return def;//4.返回结果

你可能感兴趣的:(js)