Chinaunix首页 | 论坛 | 博客
  • 博客访问: 566769
  • 博文数量: 109
  • 博客积分: 2300
  • 博客等级: 大尉
  • 技术积分: 810
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-02 13:11
文章分类

全部博文(109)

文章存档

2012年(1)

2011年(17)

2010年(62)

2009年(29)

我的朋友

分类: Java

2010-08-28 18:19:05

/**********************************************************************
submit button的响应函数
**********************************************************************/
function ValidateCtrlAndSubmit(ctrlList,isAsync)
//check and submit
{
     //change
    if(g_lockLink)
//if this submit button is locked
    {
      WS("LOCKED..."); //LOCKED...
   
      return;
    }


    if(isAsync==null)
      isAsync=false; //is not asynchronous

    var res=true;

    for(var key in ctrlList)

    {
      var obj=ctrlList[key];

      if(obj.active)
//if the object is active
      {
        res=obj.IsPass(); //the object is pass,the give value TURE to res
                          //just to check each object
        if(!res)

        {
          return res;
        }
      }
    }


    if(MY_BEFORE_SUBMIT()==false)
//something should be checked before submit
    {
      return false;
    }


//check-work ends

//send-work starts

    g_httpOK=true;
    var o=c_iniUrl;    //the variable which would be sent
    var len=g_MaxSubmitLen; //command length
   
    for(var key in ctrlList)
//try to send the commands to the server
    {
      var obj=ctrlList[key];
     
      if(obj.active)
//if this object is active
      {
        var str=GetSetterCmd(obj,GetCtrlValue(ctrlList,key)); //get command
        len-=str.length; //the length lefted
        o+=str; //command be added
  
        if(len<10)
//the space almost full,so could be sent
        {
          SendHttp(o,isAsync); //the communication between both ends
      
          if(g_httpOK)
//if sent successfully,then try to send the next command
          {
            o=c_iniUrl;
            len=g_MaxSubmitLen;
          }

          else

          {
            break;
          }
        }

      }

    }


    if(len!=g_MaxSubmitLen)
//send the commands remains
    {
      SendHttp(o,isAsync);
    }


    if(g_httpOK)
//sent successfully
    {
      MY_SUBMIT_OK();
    }

}


/*******************************************************************************
客户端向服务器发送请求的函数
*******************************************************************************/
function SendHttp(url,isAsync,callBack)

{
    isAsync=new Boolean(isAsync);
    g_SubmitHttp=null;
    g_SubmitHttp=InitXHttp(); //check the browser versions,e.g. Microsoft.XMLHTTP,
                               // and create the request

    if(callBack!=null)
//set the processing function
    {
      g_SubmitHttp.onreadystatechange=callBack; //the processing function
    }

    else
    
    {
      g_SubmitHttp.onreadystatechange=OnSubmitReadyStateProcess; //the processing function
    }


    try

    {
      g_SubmitHttp.open("GET",url,isAsync); //open the url,and get the message
      g_SubmitHttp.setRequestHeader("If-Modified-Since","0"); //set request header
      g_SubmitHttp.send(null); //send the information to the server
      WS(GL("sending_")); //waiting
    }

    catch(e)
    {
    };

}


/*************************************************************
检测浏览器,并创建请求
*************************************************************/
function InitXHttp()

{
    var xhttp=null;

    if(IsMozilla())

    {
      xhttp=new XMLHttpRequest();

      if(xhttp.overrideMimeType)

      {
        xhttp.overrideMimeType('text/xml');
      }

    }

    else
      if(browser_IE)

      {
        try

        {
          xhttp=new ActiveXObject("Msxml2.XMLHTTP");
        }


        catch(e)

        {
          try

          {
            xhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }


          catch(e)
          {
          };

        }

      }


    return xhttp;
}


/***********************************************************************
对服务器响应的数据的处理
***********************************************************************/
function OnSubmitReadyStateProcess()
//processing function
{
    if(g_SubmitHttp.readyState==4)
//if the server has responded
    {
      if(g_SubmitHttp.status!=200)
//if the server is not ready
      {
        alert(GL(err_submit_fail));
        g_httpOK=false; //then we cann't send information
        WS(GL(fail_));
      }

      else
//if the status be OK,then we could do our sending-work continually
      {
        g_httpOK=true;
        WS(GL(ok_));
      }

    }
}

阅读(1908) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~