posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

javascript ajax

Posted on 2008-08-16 18:15 G_G 阅读(467) 评论(2)  编辑  收藏 所属分类: javascript


<? xml version="1.0" encoding="utf8"  ?>
<% @ page language = " java "  contentType = " text/html; charset=utf8 "  pageEncoding = " utf8 " %>
<% @taglib uri = " /WEB-INF/struts-tags.tld "  prefix = " s " %>
<% @taglib uri = " /WEB-INF/ljw.tld "  prefix = " ljw " %>
    

<% @page import = " com.ljw.bean.CorrectionWrong " %>
<% @page import = " com.ljw.bean.CorrectionWrong.State " %>
<% @page import = " com.opensymphony.xwork2.util.ValueStack " %> < html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf8"   />
< title > Insert title here </ title >
< script  type ="text/javascript"  src ="../js/prototype.js" ></ script >
< script  type ="text/javascript"  src ="../js/jsMsg.jsp" ></ script >
< script  type ="text/javascript"  src ="../js/comm.js" ></ script >
< SCRIPT  language =JavaScript  src ="../js/supertable/dialog.js"  type =Text/JavaScript ></ SCRIPT >
</ head >
< body >
< div  id ="communityDiv" >
< s:set  name ="" ></ s:set >
< s:iterator  id ="d"  value ="%{pageList.objectList}" >
    用户名字:
< s:property  value ="#d.userInfo.userName" />< br >
    url:
< s:property  value ="#d.url" />< br >
    状态:
< s:property  value ="#d.ecwState.value" />< br >
    纠错:
< s:property  value ="#d.cwArticle" /></ br >
    编辑输入:
< textarea  rows ="10"  cols ="50"  id ='<s:property  value ="#d.id" /> ' > < s:property  value ="#d.boardmasterDesc" /></ textarea >
    
< input  type ="button"  onclick ="getUpdate('<s:property value=" #d.id" /> ')"/>
< hr />
</ s:iterator >
< br />
< ljw:pages  value ="%{pageList.pages}"  javaScript ="loadCommunityListUrl" />
</ div >
</ body >
< script  type ="text/javascript" >
function  loadCommunityListUrl(url) {
     $('communityDiv').innerHTML 
=  pageLoadingCenter;
      
var  urls  =  getActionName(url);
      
var  pars  =  getActionPars(url);
      
var  myAjax  =   new  Ajax.Updater( " communityDiv " , urls, {method: 'post', parameters: pars});
    }
var  request  =   false ;
try  {
  request 
=   new  XMLHttpRequest();
catch  (trymicrosoft) {
  
try  {
    request 
=   new  ActiveXObject( " Msxml2.XMLHTTP " );
  } 
catch  (othermicrosoft) {
    
try  {
      request 
=   new  ActiveXObject( " Microsoft.XMLHTTP " );
    } 
catch  (failed) {
      request 
=   false ;
    }  
  }
}
if  ( ! request)
  alert(
" Error initializing XMLHttpRequest! " );
  
var  _robj  =   null  ;
function  getUpdate(ki) {
  _robj 
=  document.getElementById(ki) ;
  
var  urls  = 'cwmain. do ';
  
var  pars  =  'c = ajaxUpdateByBoardMaster & cwId = ' + ki + ' & boardMasterDesc = ' + _robj.value ;
  request.open(
" POST " , urls,  true );
  request.setRequestHeader(
" Cache-Control " , " no-cache " );
  request.setRequestHeader(
" content-type " , " application/x-www-form-urlencoded " );
  request.send(pars);
  request.onreadystatechange 
=
 updatePage;
}




function  updatePage() {
    
if  (request.readyState  ==   4 ) {
        
if  (request.status  ==   200   ||  request.status == 0  ) {
            alert(request.responseText);
            eval('
var  ajaxData  = ' + request.responseText);
            
if ( ajaxData.isUpdate ){
                 alert( '更新成功!' );
            }
else {
                alert( '更新不成功!' );
            }
        } 
    }
}



</ script >
</ html >


评论

# re: javascript ajax  回复  更多评论   

2008-11-04 00:07 by 刘凯毅
    /* ajax 使用   
        AjaxFunction('url?param=tt&param2=te',function(text){  
            alert(text);
        });
     */
    var _request ;    
    try {this._request = new XMLHttpRequest(); }catch(e){
        try {this._request = new ActiveXObject('Msxml2.XMLHTTP'); }catch(e){
            try {this._request = new ActiveXObject('Microsoft.XMLHTTP'); }catch(e){request = false ;}
        }
    }
        
    var AjaxFunction = function(urls,getAjaxText){
        AjaxFunction._getAjaxText = null ;
        
        _url = '';
        _params = '';

        
        AjaxFunction._getAjaxText = getAjaxText ;
        var strs = urls.split(/"?/);
        _url = strs[0] ;
        if( strs.length>1 )
            _params = strs[1] ;
            
        _request.open("POST",this._url,true);
        _request.setRequestHeader("Cache-Control","no-cache");
        _request.setRequestHeader("content-type","application/x-www-form-urlencoded");
        //this._request.setRequestHeader("Content-Type","text/html;charset=utf8");
        _request.send(_params);
        _request.onreadystatechange = _onComplete ;
    } ;
   function _onComplete(){
        if(_request.readyState==4){
            if(_request.status==200||_request.status==0) {
                AjaxFunction._getAjaxText(_request.responseText);
            }
        }
    }

# re: javascript ajax  回复  更多评论   

2009-10-23 17:32 by 刘凯毅
<html>
<body>
<a id='pi' onclick="getCustomerInfo();" value="text"> text </a>
<div id='div1' >cxc</div>
</body>

<script type="text/javascript">

var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");

var cc =">>";
function getCustomerInfo() {
cc="xx"+cc;
var url = "t.html" ;
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}

function updatePage() {
if (request.readyState == 4) {
if (request.status == 200 || request.status==0) {
document.getElementById('div1').innerHTML+=cc+request.responseText ;
}
}
}


getCustomerInfo();
</script>

</html>

只有注册用户登录后才能发表评论。


网站导航: