无法获得完整的js文件

GavinLi 2006-08-29 10:53:29
为什么我通过HTTPxmlRequest "GET"服务器上的一个js文件,得到的文件内容不完整呢(取responseText的值)?
js文件大小为6.62k,是不是get方法有大小限制啊?该如何解决呢?????
...全文
299 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenjf2000 2006-08-29
  • 打赏
  • 举报
回复
o
shenjf2000 2006-08-29
  • 打赏
  • 举报
回复
这个问题同是否eval无关,你alert出来的内容同js内容不一致说明ajax取得的数据就不对,就不用考虑后面的执行是否正确,缩小范围检查。xuzuning(唠叨)说的方法也是让你检查ajax取得的数据长度,因此你注意力就在这个方面,看看requestHelper对象中的getDoc方法是怎样实现的等等。
GavinLi 2006-08-29
  • 打赏
  • 举报
回复
问题已经找到,是js文件有问题。谢谢大家^_^
GavinLi 2006-08-29
  • 打赏
  • 举报
回复
To xuzuning(唠叨):
我是放在header对象下面,可以不用eval。
shenjf2000 2006-08-29
  • 打赏
  • 举报
回复
你使用的RequestHelper对象是一个封装好的js对象,不知道是否这个里面出了问题,可能是它的getDoc不对,lz跟踪调试一下看看。因为你的XMLHTTPRequest对象及调用是封装在这个里面的,另外你使用的是同步调用,它这个对同步调用的处理可能有点问题。
xuzuning 2006-08-29
  • 打赏
  • 举报
回复
检查返回数据的长度
alert(obj.responseText.length);

注意,返回的是文本!需要用eval使之生效
GavinLi 2006-08-29
  • 打赏
  • 举报
回复
//动态装载js文件对象
function JsFileHelper()
{
this.loadFile = loadFile;
this.loadJsFile = loadJsFile;//动态装载js文件函数
this.loadCssFile = loadCssFile;//动态装载css文件函数
}

function loadFile(fileName,path)
{
var xDoc = null;
var url ="Client/BLL/"+fileName;
var params = "";
var httpMethod = "GET";
var docType = "txt";

if ( path )
url = path+"/"+fileName;

var oRequest = new RequestHelper();
oRequest.sendRequest(url,params,httpMethod,docType,false,null);

xDoc = oRequest.getDoc();

return xDoc;
}

function loadJsFile(objectID,fileName,path)
{
var oHead = null;
var oScript= document.getElementById(objectID);
if ( !oScript )
{
oHead = document.getElementsByTagName('head')[0];
oScript = document.createElement('script');
oScript.id = objectID;
oScript.type = "text/javascript";
oScript.text = this.loadFile(fileName,path);
oHead.appendChild(oScript);
}

if ( objectID == "AdminProduct" )
{
alert(oScript.text);
}
}

function loadCssFile(objectID,fileName,path)
{
var oHead = null;
var oScript= document.getElementById(objectID);
if ( !oScript )
{
oHead = document.getElementsByTagName('head')[0];
oScript = document.createElement('link');
oScript.id = objectID;
oScript.type = "text/css";
oScript.rel = "stylesheet";
oScript.href = path+"/"+fileName;//this.loadFile(fileName,path);
oHead.appendChild(oScript);
}
}
GavinLi 2006-08-29
  • 打赏
  • 举报
回复
调用的方法如下(因为涉及到太多的js对象,贴完就太多啦,请大家自己试试看看):
function updateProduct(ID)
{
oBaseInfo.ID = ID;
oBaseInfo.file.loadJsFile("AdminProduct","AdminProduct.js",null); //这里请求js文件
if ( !this.oAdminProductForm)
this.oAdminProductForm = new AdminProductForm();//这里new js文件定义的对象

//this.oAdminProductForm.loadAdminProductFormUI();
//this.oAdminProductForm.iniProductControls();
//this.oAdminProductForm.getProductDetail();
}
GavinLi 2006-08-29
  • 打赏
  • 举报
回复
To shenjf2000(一路走来):
已经察看过啦,alert的内容和原文件的内容不一致。我就奇怪了,有个js文件大小为6.73k,都可以照样get得到完整内容,为什么我这个js文件不得呢,怪了。难道是我写法有问题嘛?
js文件内容如下如下,请大家试试:
function AdminProductForm()
{
this.ddlFirstType = null;
this.ddlSecondType = null;
this.txtName = null;
this.txtDesc = null;
this.iniProductControls = iniProductControls;
this.getFirstProductType = getFirstProductType;
this.getSecondProductType = getSecondProductType;
this.getAdminProductFormUI = getAdminProductFormUI;
this.loadAdminProductFormUI= loadAdminProductFormUI;
this.getProductDetail=getProductDetail;
this.saveProduct = saveProduct;
this.deleteProduct = deleteProduct;
this.changeFirstProductType = changeFirstProductType;
this.checkProductInfo = checkProductInfo;
}
function getAdminProductFormUI()
{
oBaseInfo.createContainer();
var xDoc = oBaseInfo.sendMyRequest("Template/AdminProduct.html","GET","","txt",false,null);
oBaseInfo.container.innerHTML = xDoc;
}
function loadAdminProductFormUI()
{
var containerBody = document.getElementById("divBody");
var xDoc = oBaseInfo.sendMyRequest("Template/AdminProduct.html","GET","","txt",false,null);
containerBody.innerHTML = xDoc;
}
function getProductDetail()
{
var oDocHelper = null;
var ddlFirstValue = null;
var ddlSecondValue= null;
var url = "Server/BLL.asp?formID="+P_DETAIL+"&id="+oBaseInfo.ID+"&action=update";
var xDoc = oBaseInfo.sendMyRequest(url,"GET",null,"xml",false,null);
if ( xDoc )
{
oDocHelper = new DocHelper(xDoc);
this.txtName.value = oDocHelper.getValue("name",0);
this.txtDesc.value = oDocHelper.getValue("description",0);
ddlFirstValue = oDocHelper.getValue("category",0);
ddlSecondValue = oDocHelper.getValue("subcategory",0);
for ( var i=0;i < this.ddlFirstType.options.length; i++ )
{
if ( this.ddlFirstType.options[i].text == ddlFirstValue )
{
this.ddlFirstType.[i].selected = true;
break;
}
}
this.changeFirstProductType();
for ( var i=0;i < this.ddlSecondType.options.length; i++ )
{
if ( this.ddlSecondType.options[i].text == ddlSecondValue )
{
this.ddlSecondType.[i].selected = true;
break;
}
}
}
}
function iniProductControls()
{
this.ddlFirstType = document.getElementById("ddlFirstItems");
this.ddlSecondType = document.getElementById("ddlSecondItems");
this.txtName = document.getElementById("txtProductName");
this.txtDesc = document.getElementById("txtDesc");
oBaseInfo.ActionType = "ADD";
this.getFirstProductType();
}
function getFirstProductType()
{
var nodeList = null;
var url = "Server/BLL.asp?formID="+F_FMENU;
var myDoc = oBaseInfo.sendMyRequest(url,"GET","","xml",false,null);
if ( myDoc )
{
nodeList = myDoc.documentElement.selectNodes("//TreeNode");
for ( var i = 0; i < nodeList.length; i++ )
{
var option = document.createElement( "OPTION" );
option.innerText = nodeList[i].getAttribute("text");
option.value = nodeList[i].getAttribute("id");
this.ddlFirstType.appendChild(option);
}
}
}
function getSecondProductType()
{
var nodeList = null;
var url = "Server/BLL.asp?formID="+F_SMENU+"&id="+this.ddlFirstType.options[this.ddlFirstType.selectedIndex].value;
var myDoc = oBaseInfo.sendMyRequest(url,"GET","","xml",false,null);
if ( myDoc )
{
this.ddlSecondType.length=0;
nodeList = myDoc.documentElement.selectNodes("//TreeNode");
for ( var i = 0; i < nodeList.length; i++ )
{
var option = document.createElement( "OPTION" );
option.innerText = nodeList[i].getAttribute("text");
option.value = nodeList[i].getAttribute("id");
this.ddlSecondType.appendChild(option);
}
}
}
function checkProductInfo()
{
var iTypeID = null;
var sName = null;
var sDesc = null;
sName = this.txtName.value;
sDesc = this.txtDesc.value;
iTypeID = this.ddlSecondType.selectedIndex;
if ( sName == "" )
{
oBaseInfo.alertMessage(E_EMPTY_NAME);
return false;
}
if ( sDesc == "" )
{
oBaseInfo.alertMessage(E_EMPTY_DESC);
return false;
}
if ( iTypeID < 0 )
{
oBaseInfo.alertMessage(E_EMPTY_TYPE);
return false;
}
}
function saveProduct()
{
var bFlag = false;
var iID = null;
var iTypeID = null;
var sName = null;
var sDesc = null;
var params = null;
var oDocHelper = null;
var xDoc = null;
var url = null;

if ( this.checkProductInfo() == false )
return;
sName = escape(this.txtName.value);
sDesc = escape(this.txtDesc.value);
iTypeID = this.ddlSecondType.options[this.ddlSecondType.selectedIndex].value;
params = "typeid="+iTypeID+"&name="+sName+"&desc="+sDesc;
if ( oBaseInfo.ActionType =="UPDATE" )
{
iID = oBaseInfo.ID;
params = params+"&id="+iID;
url = "Server/BLL.asp?formID="+F_UPDATE_PRODUCT+"&action=update";
}
else
{
url = "Server/BLL.asp?formID="+F_ADD_PRODUCT+"&action=add";
}
xDoc = oBaseInfo.sendMyRequest(url,"POST",params,"xml",false,null);
if ( xDoc )
{
oDocHelper = new DocHelper(xDoc);
if ( oDocHelper.getValue("AdminProduct",0) =="true" )
bFlag = true;
else
bFlag = false;
}
if ( bFlag == true )
{
oBaseInfo.alertMessage(null);
}
else
{
oBaseInfo.alertMessage(E_SAVE_FAILURE);
}
}
function deleteProduct(isFirstType)
{
var bFlag = false;
var iID = null;
var params = null;
var oDocHelper = null;
var xDoc = null;
var url = null;
iID = oBaseInfo.ID;
url = "Server/BLL.asp?formID="+F_DELETE_PRODUCT+"&action=delete";
params = "id="+iID;
xDoc = oBaseInfo.sendMyRequest(url,"POST",params,"xml",false,null);
if ( xDoc )
{
oDocHelper = new DocHelper(xDoc);
if ( oDocHelper.getValue("AdminProduct",0) =="true" )
bFlag = true;
else
bFlag = false;
}
if ( bFlag == true )
{
oBaseInfo.formID = P_PRODUCT_LIST;
oBaseInfo.loadForm();
}
else
{
oBaseInfo.alertMessage(E_DELETE_FAILURE);
}
}
function changeFirstProductType()
{
this.getSecondProductType();
}
shenjf2000 2006-08-29
  • 打赏
  • 举报
回复
不过我觉得是get方法的可能性较小,也许不是得到文件内容不完整,而是你的js页面有问题。你先直接用ie看看你输出的js内容,然后在应用页面alert(XMLHttpreuest.responseText)看看是否一致。
shenjf2000 2006-08-29
  • 打赏
  • 举报
回复
有可能,不过get方法是发送的字节数有限制而不是接受的,你先试试POST方法看看。

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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