JqueryMoblie 之 loading

显示“正在加载........”等字样,并且带有加载图片的显示。

//显示加载器
function showLoader() {
  $.mobile.loading('show', {
    text: '正在提交...', //加载器中显示的文字
    textVisible: true, //是否显示文字
    theme: 'd', //加载器主题样式a-e
    textonly: false, //是否只显示文字
    html: "" //要显示的html内容,如图片等
  });
}

隐藏“正在加载......”和图标

function hideLoader()
{
  //隐藏加载器
  $.mobile.loading('hide');
}

请求如下:

 showLoader();

$.ajax({
type : "post",
async : true,
url : "test.jsp?orderId="+orderData.orderId+"&sinalSign="+sinalSign,
dataType : "json",
success : function(json) {
  if (json.returnState) {
  } else {
    $("#warnSubmit").html("<font color='red'>(出租失败)</font>");
  }
  hideLoader();
},
error : function() {
  $("#warnSubmit").html("<font color='red'>(出租失败)</font>");
  hideLoader();
}
});

注:在一个请求中,往往在请求之前显示loading,在获得结果后隐藏loading,应当注意的是,由于请求是异步的,所以需要在请求发起之前调用showLoader,在请求中的结果处理中调用hideLoader,而不是在请求代码外调用hideLoader,否则loading不会显示。

原文地址:https://www.cnblogs.com/ScorchingSun/p/3899430.html