js向后台请求方式
1 if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
var url =请求的全路径
xmlHttp.open("post",url,true);
xmlHttp.onreadystatechange=function (){
if(xmlHttp.status != 200){//错误处理
window.location.href= path+"/chart/err.jsp?eid=1";
}
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
responseJson = xmlHttp.responseText;
var myResponseJson = eval('('+responseJson+')')[0];
dArray = eval('('+myResponseJson.datelistjson+')');
sf = eval('('+myResponseJson.sfArray+')');
headkey = eval('('+myResponseJson.zhibiaoArray+')');
head = eval('('+myResponseJson.title+')');
$ID("pageNO").value = myResponseJson.pageno;
$ID("pageSize").value = myResponseJson.pagesize;
$ID("dataCount").value = myResponseJson.datacount;
ctable(dArray,filed,flag);
$RENDER_PAGETURN(myResponseJson.pageno,myResponseJson.pagesize,myResponseJson.datacount,"pageShowDiv",setPageValuez);
$("#TaskListTable").changeBgColor({});
initstyle.init($ID("TaskListTable"));
$UNLOAD_PAGE();
}
}
xmlHttp.send(null);
2$.ajax({ url: path+'/taskv4/taskListAjax.action',type:"POST",cache: false,data: $('#taskListForm').serialize(),success: function(rsData){if(rsData=="timeout"){window.location.href= path+"/chart/err.jsp?eid=1"; return;}else if(rsData=="error"){window.location.href= path+"/chart/err.jsp?eid=100"; return;}var dataObj = eval('(' + rsData + ')');$('#TaskListTable').load(path+"/taskv4/TaskListTable.jsp",function(){//SetRoleListValue(dataObj);//$ID("pageNO").value = dataObj.pageNO;//$ID("pageSize").value = dataObj.pageSize;//$ID("dataCount").value = dataObj.dataCount;//$RENDER_PAGETURN(dataObj.pageNO,dataObj.pageSize,dataObj.dataCount,setPageValue);//$("#RoleTaskList").changeBgColor({});//initstyle.init($ID("TaskListTable"));//$ID("SelAll").setchecknew(false);advancedSelectValue = dataObj;setRoleListValuePublic(dataObj);$UNLOAD_PAGE();});},error:function(XmlHttpRequest,textStatus,errorThrown){ $UNLOAD_PAGE(); var openurl = path+'/chart/err.jsp?eid=100'; window.open(openurl,'_self');}});