HttpRequest 动态加载asp页面

itzhiren 2008-03-21 03:28:40
this.doSendResuest=function(urlPar,methodPar,obj,domPar,asyPar){
if(obj._error){
return;
}
// alert("url is :"+urlPar);
methodPar=((methodPar)?methodPar:"GET");
asyPar=((asyPar)?asyPar:true);
this._domResult=(domPar)?domPar:obj._domResult;
try{
var a=this._getRequestObj();
a.onreadystatechange=function(){
if(obj._error){
return;
}
var readyStateTmp=a.readyState;
if(readyStateTmp==0){
obj._setMessage("未初始化!");
}else if(readyStateTmp==1){
obj._setMessage("正在读取中......");
}else if(readyStateTmp==2){
obj._setMessage("已经读取过!");
}else if(readyStateTmp==3){
obj._setMessage("正在逐个切换......");
}else if(readyStateTmp==4){
var statusTmp=a.status;
if(statusTmp==404){
obj._setMessage("未找到请求页面!",true);
}else if(window.location.href.indexOf("http")==-1 || statusTmp==200){
obj._setMessage("完成!");
if(this._domResult && window.XMLHttpRequest){
obj._requestResult=a.responseXml;
}else{
obj._requestResult=a.responseText;
// alert("responseText:"+a.responseText);
}
if(obj._callBack){
obj.doCallBack();
}
}else{
// alert("未知错误!");
obj._setMessage("未知错误!");
}
}else{
obj._setMessage("未知错误!");
}
}
a.open(methodPar,urlPar,asyPar);
a.setRequestHeader("If-Modified-Since","0");
a.send(obj._requestData);
}catch(ex){
obj._setMessage(ex,true);
}
}


==========================================================
function getFlagInfo1(tagid,i,s){
var url;
if(tagid == "tab3"){
if(i == 1)
url="../main/TabView.asp?id=newspaper1&season="+s;
else if(i == 3)
url="../main/TabView.asp?id=newspaper2&season="+s;
else if(i == 5)
url="../main/TabView.asp?id=newspaper3&season="+s;
else if(i == 7)
url="../main/TabView.asp?id=newspaper4&season="+s;
else
alert("bad tab pressed");
}
// alert(url);
var xmlhttp=new HttpRequest();
var loadstatustext="<div class='loading'><img src='../images/loading.gif' /> 正在加载内容, 请稍候...</div>";
getObject(tagid+'_cnt').innerHTML = loadstatustext;
with(xmlhttp){
init();
doSetCallBack(setFlagInfo,tagid);
doSendResuest(url,"GET",xmlhttp);
// alert(url);
}
}
其中url有值(../main/TabView.asp?id=newspaper1&season=19)
xmlhttp创建成功

====================================================

但是调用这个 getFlagInfo1 的时候,总是显示不出 url 所对应的页面信息,而且也没有错误提示
...全文
495 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞天神笔 2008-03-28
  • 打赏
  • 举报
回复
向13楼学习!
itzhiren 2008-03-26
  • 打赏
  • 举报
回复
多谢各位!

Go 旅城通票 2008-03-26
  • 打赏
  • 举报
回复
你可以先试试楼上的设置响应头,如果不行了再改为xml作为载体..

ajax就是js和xml,一般来说用xml作为载体不会出现乱码的问题.
Go 旅城通票 2008-03-25
  • 打赏
  • 举报
回复
使用xml作为载体试试,如果直接使用responseText很容易出现乱码,而且注意设置一下页面为统一的编码

<?xml version='1.0' encoding='gb2312'?>
<body>
<![CDATA[返回的信息,在此节点中可以使用任何标签]]>
</body>
itzhiren 2008-03-25
  • 打赏
  • 举报
回复
怎样解决乱码问题?我查了几种方法,都不管用
yorloo 2008-03-25
  • 打赏
  • 举报
回复
要是我没说错的话,多给点分吧,现在穷,等着分数来下载《Visual C++程序开发范例宝典》呐。找遍整个地球就只在这里看得到。
yorloo 2008-03-25
  • 打赏
  • 举报
回复
在TabView.asp文件的开头加入以下两句就可以了。AJAX默认用UTF-8进行编码,浏览器一般默认是GB2312,所以会乱码。在文件头里指定编码信息以后就不会了。
<%
Response.ContentType="text/html"
Response.Charset="GB2312"
%>
itzhiren 2008-03-25
  • 打赏
  • 举报
回复
单独运行被加载的页面 TabView.asp 是可以正确显示的,但是在页面index.asp中加载以后就显示乱码了
itzhiren 2008-03-25
  • 打赏
  • 举报
回复
不太明白,请大侠明示
itzhiren 2008-03-21
  • 打赏
  • 举报
回复
我把url页面的文件头什么的都去掉了,只剩下table就可以显示内容,但是内容却是乱码
银狐被占用 2008-03-21
  • 打赏
  • 举报
回复
getObject(tagid+'_cnt').innerHTML =doSendResuest(url,"GET",xmlhttp);
itzhiren 2008-03-21
  • 打赏
  • 举报
回复
/**********************************************
* @author skyz
* @function javascript client ajax dealwith
* @datetime 2006-3-20
**********************************************
* Function: Create a httpRequest object
**********************************************/
function HttpRequest(){
this._httpRequest=null; //HttpRequest request object
this._callBack=null; //Call back function
this._domResult=true; //Result if dom object or text string
this._requestData=null; //Request data
this._requestResult=null; //HttpRequest result
this._stateString=null; //Current request state string
this._error=false; //Current if have error
this._callBackPara=null; //Current callback function parama
//internal method for get HttpRequestObject
this.init=function(){
//Judge if Not IE
if(window.XMLHttpRequest){
this._httpRequest=new XMLHttpRequest();
//Set request mime is text/xml
if(this._httpRequest.overrideMimeType){
this._httpRequest.overrideMimeType('text/xml');
}
}else if(window.ActiveXObject){
try{
this._httpRequest=new ActiveXObject("Msxml2.XMLHTTP");
}catch(ex){
try{
this._httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}catch(ex){
this._setMessage(ex,true);
return;
}
}
}
//Judge HttpRequest object create successful
if(!this._httpRequest){
this._setMessage("XMLHttpRequest 对象创建失败!请重试......",true);
return;
}
}
/*
* Function: Set the request header
* namePar:request's header name
* valuePar:request's header value
*/
this.doSetRequestHeader=function(namePar,valuePar){
if(this._error){
return;
}
this._httpRequest.setRequestHeader(namePar,valuePar);
}
/*
* Function: Set the request data
* dataPar:request's send data;
*/
this.doSetRequestData=function(dataPar){
if(this._error){
return;
}
this._requestData=dataPar;
}
/*
*Function get RequestHttp Object
*/
this._getRequestObj=function(){
if(this._error){
return;
}
return this._httpRequest;
}
/*
* Function:Set Callback function para
*/
this.doSetCallBack=function(callBack,paraData){
this._callBack=(callBack)?callBack:null;
this._callBackPara=(paraData)?paraData:null;
};
/*
* Function: Get current stateString
*/
this.doGetState=function(){
return this._stateString;
}
/*
* Function: get current Error
*/
this.doGetError=function(){
return this._error;
}
/*
*
*/
this.doCallBack=function(){
this._callBack(this._requestResult,this._callBackPara);
}

/*
* Function: Send the request
* urlPar: request's url path
* [methodPar]:request's method
* [domPar]: request's result is dom or string
*/
this.doSendResuest=function(urlPar,methodPar,obj,domPar,asyPar){
if(obj._error){
return;
}
// alert("url is :"+urlPar);
methodPar=((methodPar)?methodPar:"GET");
asyPar=((asyPar)?asyPar:true);
this._domResult=(domPar)?domPar:obj._domResult;
try{
var a=this._getRequestObj();
a.onreadystatechange=function(){
if(obj._error){
return;
}
var readyStateTmp=a.readyState;
if(readyStateTmp==0){
obj._setMessage("未初始化!");
}else if(readyStateTmp==1){
obj._setMessage("正在读取中......");
}else if(readyStateTmp==2){
obj._setMessage("已经读取过!");
}else if(readyStateTmp==3){
obj._setMessage("正在逐个切换......");
}else if(readyStateTmp==4){
var statusTmp=a.status;
if(statusTmp==404){
obj._setMessage("未找到请求页面!",true);
}else if(window.location.href.indexOf("http")==-1 || statusTmp==200){
obj._setMessage("完成!");
if(this._domResult && window.XMLHttpRequest){
obj._requestResult=a.responseXml;
// alert("responseXml:"+a.responseXml);
}else{
obj._requestResult=a.responseText;
//alert("responseText:"+obj._requestResult);

}
if(obj._callBack){
obj.doCallBack();
}
//alert("responseText:"+obj._requestResult);
}else{
// alert("未知错误!");
obj._setMessage("未知错误!");
}
//alert("responseText:"+obj._requestResult);
}else{
obj._setMessage("未知错误!");
}
//alert("responseText:"+obj._requestResult);
}
a.open(methodPar,urlPar,asyPar);
a.setRequestHeader("If-Modified-Since","0");
a.send(obj._requestData);
// a.send(obj._requestResult);
//alert(obj._requestResult);
}catch(ex){
obj._setMessage(ex,true);
}
}
/*
* Function: Deal exception error
* exPar:error string
*/
this._setMessage=function(exPar,mark){
this._stateString=exPar.toString();
this._error=(mark)?mark:false;
}
}


这就是全部内容
Go 旅城通票 2008-03-21
  • 打赏
  • 举报
回复
HttpRequest()函数 内容帖出来看看,如果只是返回ajaxobj的话,你的参数obj当然没有_requestData这个属性,所以为空.
itzhiren 2008-03-21
  • 打赏
  • 举报
回复
不对,最后的 a.send(obj._requestData); 其中 obj._requestData 是null ,为什么呢?
itzhiren 2008-03-21
  • 打赏
  • 举报
回复
取出了页面内容,但没显示
银狐被占用 2008-03-21
  • 打赏
  • 举报
回复
看doSendResuest是否取出了页面的内容。。
alert一下.
银狐被占用 2008-03-21
  • 打赏
  • 举报
回复
TabView.asp这个页清缓存没
MoAspEnginer更新日志: 2015-11-30: 优化核心的IO读取; view2.js增加for循环对自定义数据的支持; 优化post和get对数字列表的读取; 优化控制台,可调式多APP; 修复expression解析Empty方法的bug; 优化view2; MoAspEnginer MVC框架简介 MoAspEnginer是一款基于JScript的ASP开源MVC框架。A JScript-based MVC framework for ASP. 单文件入口。Single entry point. 代码和程序的真正分离。A real MVC. 模板编译ASP代码。Combine template file to ASP(JScript) code. 支持类库扩展以及模板自定义标签扩展。Support Library and Tag extend. 支持多种数据库,默认支持ACCESS、MSSQL、MYSQL、SQLITE,可自定义其他类型数据库。Support Muti-Type-Databases. 支持多数据库操作。Support Muti-Databases-Operate. 表单验证支持,HTTP请求数据可直接用来更新数据库。FormValidatee is supported, and Http Post data can be used for insert or update table record(s). 提供HttpRequest,HttpUpload,Soap,OAUTH2.0等模块。"HttpRequest,HttpUpload,Soap,OAUTH2.0" are supported. 提供CryptoJS,提供AES/DES/RC4/Rabbit/pbkdf2/ripemd160等算法。CryptoJS is supported. 内置Json解析和构建。Json2 is built-in.You can use it to parse or stringify Json data. 支持多种路由方式,包括404、URL、isapi_URLRewrite,完全自定义的路由配置。URLRoute is Supported(404 Error Page, URL Route,ISAPI_URIRewrite). 路由支持REST。REST is Supported. 支持类库缓存,编译缓存,HTML缓存,数据库Model缓存。Library Cache, Combined File Cache, HTML Cache and Model Cache. 资源统一管理,统一销毁,使您专心于业务逻辑处理。You can pay much more attention on you business. 换一种ASP的开发方式!!!Get your ASP!!!   新特性(New Features) DEBUG支持,开启DEBUG模式后可查看错误的源行; 类似nodejs的模块加载方式,同时提供更灵活的使用方式 核心模块按需加载,提高加载速度; 优化模板引擎,模板编写更友好; 提供丰富的模块支持,包括Zip压缩,Gzip压缩,tar打包,xml打包,验证码(多字体),QRCode,新的ASPCookie机制等, 异常统一管理,可设置相应的ERROR_REPORTING决定显示哪些异常; 只保留入口文件和核心文件,其他模块动态加载(为了安全,可以将除入口文件和核心文件以外的所有文件放在非web目录); 常用模块(Model__,cookie,mpi,tar,base64,dump,JSON,VBS等)延迟加载,程序调用相关方法时自动加载模块。  MoAspEnginer MVC框架页面展示:   相关阅读 同类推荐:站长常用源码

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧