ajax不能在 firefox3上运行

来源:百度知道 编辑:UC知道 时间:2024/05/26 11:36:25
下面的代码在ie的各种版本都可以运行,但在Firefix3中怎么都不执行
相信我不可能是第一个遇到这个问题的人,但在网上找了好多就没有解决的办法,求老法师放个技能帮我解决

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>xmlhttprequest ajax demo</title>
<script type ="text/javascript" language ="javascript" >
var req=false; //定义变量,用来创建xmlhttprequest对象
var flag=true;//浏览器 firefox2及以下版本,IE7,opera这些浏览器为true
//firefox3中为false;
var divName;
function creatReq(url,div) // 创建xmlhttprequest,ajax开始
{
divName=div;
createReq();
if(req) //成功创建xmlhttprequest
{
if(flag){
req.open("GET",url,false); //与服务端建立连接(请求方式post或get,地址,true表示异步)
req.onreadystatechange = callback; //指定回调函数
req.send(null); //发送请求
}else{

req.open("GET",url,false);
alert('d');
r

关于XMLHttpRequest对象的open方法,MSDN里明确说明了:
Security Alert Cross-domain, cross-port, and mixed protocol requests are not allowed. The sUrl parameter may only specify XML data files in the same domain, using the same port and protocol method, as that from which the page is served.
简言之,跨域访问是不允许的
我相信即使在IE上也至少会有个警告框弹出来,只有当你选择忽略后你的代码才能在IE上正确执行。

I can't help you.