Ajax.js文件包含在jsp页面中,结果ie提示找不到对象,firefox没有问题
admin 发表于 2010-08-28 | 来源:互联网 | 阅读:

以前我用struts,但是页面还有中文字符,现在我把中文字符全部用<bean:message>写在网页里,结果ajax不灵了,在firefox下可以,在ie下就不行了,但是如果直接吧ajax写在网页里,又都可以

下面是我的userajax.js文件内容
 
 var req;

function createXMLHttpRequest() {
  if (window.ActiveXObject) {
  req = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  else if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();
  }

}

  function checkUsername(value)//使用Ajax访问服务器
  {
  createXMLHttpRequest();

if(req){
   
req.onreadystatechange=setEnValue;
  req.open("GET"," eckUsername?username="+value);//把参数带到服务器中
  req.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);
  req.send(null);
}else{
alert("XMLHttpRequest not created!!");
}
 
  }
 
  function setEnValue()
  {
  if (req.readyState==4 )//访问到服务器
  {  
  if(req.status==200)//正确返回
  {  
var v=req.responseText;
document.getElementById("userexist").innerHTML=v;
  }
else if(req.status==404){
alert("Not found!");
  }
}
 
  }

这个文件包含在jsp文件中

jsp页面: 

<SCRIPT type="text/javascript" src=http://topic.csdn.net/u/20090417/18/"/cn/js/search.js"></SCRIPT>

<td><input name="username" type="text" id="username" size="20" maxlength="20" onBlur="checkUsername(this.value)"></td>
   
  <div id="userexist" class="style1"></div>

已经有10 个评论
  1. 15375 说:

    另外,本人还有一个问题function checkSearchform(){document.searchform.searchname.focus();searchname=document.searchform.searchname.value;if (searchname == "") { window.alert("<bean:message bundle=’jsnotice’ key=’js.index.nosearchname’/>"); document.searchform.searchname.focus();   return; } document.searchform.submit();}因为我是用struts,要用到国际化功能,但不喜欢用validator验证客户端,更喜欢用js做客户端验证,我如果把以上js直接写在jsp页面上,就可以显示<bean:message bundle=’jsnotice’ key=’js.index.nosearchname’/>指定的值,但是如果把这个js作为一个js文件包含在jsp页面上,就不能显示那个key指示的值,我想问一下有没有其他的地方法显示key对应的值?

  2. hahamy 说:
  3. dbb123 说:

    没有碰到过,应该包括在里面和写在页面是一样的,看看你的那个<bean:message>会不会和JS的的一些东西有冲突

  4. sbamd 说:

    有很大的可能性是js文件中的中文注释引起的,请把js中的中文注释全部去掉。这是因为当js文件被浏览器加载的时候,由于不知道该用什么字符集来解析(没有深入研究过,我认为是以js所属的页面的字符集),有时候字符集不匹配(比如因为使用的编辑工具把js村成了UTF-8而页面指定的编码是gbk),中文字符的出现会破坏js语法。

  5. xiaobao520 说:

    http://hi.baidu.com/lael80/blog/item/5d2d835053d5a26285352449.html

  6. 天天累 说:

    那需要隐藏字段,然后在js里面取隐藏字段

  7. xydrj 说:

    非常感谢jinxfei网友,按照你的思路,就可以了!也感谢其他参与的网友!

  8. xjhuc05 说:

    非常感谢jinxfei网友,按照你的思路,就可以了! 也感谢其他参与的网友!侥幸而已,因为我自己曾经两次碰到过这个问题。

  9. liangjiaqi 说:

    关注

  10. waterskin 说:

    怎么解决的啊,怎么看不到?

我要评论

评论功能因故关闭!

请加入我们的QQ群一起参与讨论:群号59400482(500人超级群)


返回首页 | 关于我们 | 联系我们 | 广告合作 | 网站地图 | 友情链接 | 版权声明