简体   繁体   English

dajax / dajaxice中的进度指示器?

[英]Progress indicator in dajax/dajaxice?

I sucessfully integrated dajax in my project. 我成功地将dajax集成到了我的项目中。 It is fine but it lacks some features which could make it even better - eg. 很好,但是缺少一些可以使其变得更好的功能-例如。 visible indicator that the request is being processed (darken screen, hourglass, whatever). 显示正在处理请求的可见指示器(变暗的屏幕,沙漏等)。 I found some places in dajaxice.js where should I intercept the request but this is not the easy way.. Are you aware of some easy method or should I choose the hard way - to not use any ajax framework and do all the work manually? 我在dajaxice.js中找到了一些我应该拦截请求的地方,但这不是简单的方法。.您是否知道一些简单的方法,还是应该选择困难的方法-不使用任何ajax框架并手动完成所有工作?

Something like this would work (to give a gmail style loading... message in the top right corner): 这样的事情会起作用(在右上角提供gmail样式加载...消息):

function useLoadingMessage(message) {
  var loadingMessage;
  if (message) loadingMessage = message;
  else loadingMessage = "Loading";

  Dajaxice.preHook = function() {
    var disabledZone = document.getElementById('disabledZone');
    if (!disabledZone) {
      disabledZone = document.createElement('div');
      disabledZone.setAttribute('id', 'disabledZone');
      disabledZone.style.position = "absolute";
      disabledZone.style.zIndex = "1000";
      disabledZone.style.left = "0px";
      disabledZone.style.top = "0px";
      disabledZone.style.width = "100%";
      disabledZone.style.height = "100%";
      document.body.appendChild(disabledZone);
      var messageZone = document.createElement('div');
      messageZone.setAttribute('id', 'messageZone');
      messageZone.style.position = "absolute";
      messageZone.style.top = "0px";
      messageZone.style.right = "0px";
      messageZone.style.background = "red";
      messageZone.style.color = "white";
      messageZone.style.fontFamily = "Arial,Helvetica,sans-serif";
      messageZone.style.padding = "4px";
      disabledZone.appendChild(messageZone);
      var text = document.createTextNode(loadingMessage);
      messageZone.appendChild(text);
    }
    else {
      document.getElementById('messageZone').innerHTML = loadingMessage;
      disabledZone.style.visibility = 'visible';
    }
  };

  Dajaxice.postHook = function() {
    document.getElementById('disabledZone').style.visibility = 'hidden';
  };
}

Call useLoadingMessage() from your javascript document.ready script, or from the onload in your body tag for the very agnostic. 从javascript document.ready脚本或body标记中的onload调用useLoadingMessage()以确保不可知论。

A couple of hacks in the dajaxice.core.js : dajaxice.core.js中的一些技巧

Line 49 onwards: 49行起:

    oXMLHttpRequest.onreadystatechange = function() {
        if (this.readyState == XMLHttpRequest.DONE) {
            if(Dajaxice.postHook) Dajaxice.postHook();
            if(this.responseText == Dajaxice.EXCEPTION || !(this.status in Dajaxice.valid_http_responses())){
                error_callback();

Line 65 onwards: 第65行起:

    }
    if(Dajaxice.preHook) Dajaxice.preHook();
    if(method == 'POST'){
        oXMLHttpRequest.send(send_data);
    }
    else{

The javascript is all library agnostic and it should only involve adding 2 lines to the Dajaxice source. javascript是与库无关的,并且只应在Dajaxice源代码中添加2行。 If you wish to use a different loading element simply give it an id of disableZone in your html and set visible = hidden for its css. 如果您希望使用其他加载元素,只需在html中disableZone一个disableZone iddisableZone为其CSS设置visible = hidden

I took this solution from dwr , which is dajaxice for Java. 我从dwr获得了这个解决方案, dwr是Java的dajaxice。 It does have some other cool features though, like some decent debug pages and direct image uploading, which would be handy in dajaxice.... ;). 但是它确实还有其他一些很酷的功能,例如一些不错的调试页面和直接的图像上传功能,在dajaxice中非常方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM