将数据加载时显示的图片和文字提成公共的--实现方法

1. 页面引入loading.js。且在页面上添加<div ,
    url: url,
    data: data,
    success :     function(res){    
        loading.hide();
        ………………………………
        }
    });

loading.js

var loadingObj = function(viewObj, imgPathPrefix){
    var imgName = "loading_pa.gif";
    this.css = ".loading_box{background:url("+ imgPathPrefix + imgName +") center top no-repeat; padding-top:30px; 100%; font-size:12px; text-align:center; color:#cccccc;}";
    this.html = "<div class='loading_box'>正在加载中,请稍后...</div>";
    this.viewObj = viewObj;
}

loadingObj.prototype = {
    init: function(){
        var style = $("<style>"+ this.css +"</style>");
        var head = $("head").length > 0 ? $("head").eq(0) : $("head");
        style.appendTo(head);
        this.viewObj.html(this.html);
    },
    show: function(){
        this.viewObj.show();
    },
    hide: function(){
        this.viewObj.hide();
    }
};