• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Chris

萌萌的IT人
博客园 首页 新随笔 联系 订阅 订阅 管理

Ajax post basic


 1 <script language="javascript" type="text/javascript">
 2 var http_request=false;
 3
 4    function InitAjax(url,content,method)
 5    {
 6       
 7       http_request = false;
 8
 9        if (window.XMLHttpRequest) 
10        { 
11            // Mozilla, Safari,
12            http_request = new XMLHttpRequest();
13            
14                if (http_request.overrideMimeType) 
15                {
16                    http_request.overrideMimeType('text/xml');
17                }

18        }
 
19        else if (window.ActiveXObject) { // IE
20                try 
21                {
22                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
23                }
 
24                catch (e) {
25                try 
26                {
27                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
28                }
 
29                catch (e) 
30                {
31                }

32       }

33   }

34   
35    if (!http_request) 
36    {
37        alert('Giving up :( Cannot create an XMLHTTP instance');
38        return false;
39    }

40  
41    http_request.onreadystatechange = method;
42    http_request.open('POST', url,true);
43    window.status="正在请求数据";   
44    http_request.send(content);
45}

46
47function OnAjaxPostBack()
48{
49    //readyState的取值如下: 
50  //0 (未初始化) 
51  //1 (正在装载) 
52  //2 (装载完毕) 
53  //3 (交互中) 
54  //4 (完成) 
55  
56    if (http_request.readyState == 4) 
57    {
58        if (http_request.status == 200) 
59        {            
60            window.status="正在加载数据"
61            if(http_request.responseText.length>0 && !isNaN(parseInt(http_request.responseText,10)))
62            {
63                
64                document.all("ctl00_cphMain_gvReportDetail_ctl"+GetTBitNum(feerowindex)+"_txtItem"+feecolumnindex).value=http_request.responseText;
65                            }

66            else
67            {
68                alert(http_request.responseText);
69                document.all("ctl00_cphMain_gvReportDetail_ctl"+GetTBitNum(feerowindex)+"_txtItem"+(feecolumnindex-1)).value=""; 
70                document.all("ctl00_cphMain_gvReportDetail_ctl"+GetTBitNum(feerowindex)+"_txtItem"+(feecolumnindex)).value="";                 
71            }

72           
73            window.status="成功获取数据";
74           
75        }
 
76        else 
77        {
78            window.status="请求失败";
79            document.all("ctl00_cphMain_gvReportDetail_ctl"+GetTBitNum(feerowindex)+"_txtItem"+(feecolumnindex-1)).value="";
80            document.all("ctl00_cphMain_gvReportDetail_ctl"+GetTBitNum(feerowindex)+"_txtItem"+(feecolumnindex)).value="";
81        }

82    }
 
83    
84     var rc=Number("<%= CurrentRowsCount %>");
85       
86       SyncTotal(feerowindex,feecolumnindex-4,rc);     
87   
88}

89</script>
发表于 2007-08-15 09:15  陆兵  阅读(168)  评论(0)    收藏  举报
 
刷新页面返回顶部

公告


Powered By 博客园