在线询问--关于ajax跨域访问--十万火急!!

muyaoray 2008-11-27 08:07:06
代码如下:在apache 下面的代码
<html>
<head>
<script type="text/javascript">

function creatConnect(urlMsg)
{
var ajax=null;
try{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1)
{
try
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e2)
{
}

}
if(!ajax && typeof XMLHttpRequest != 'undefined'){
ajax = new XMLHttpRequest();
}
if(urlMsg.indexOf("?")>0){
urlMsg += "&randnum=" + Math.random();
}else{
urlMsg += "?randnum=" + Math.random();
}
ajax.open("GET",urlMsg,true);

ajax.onreadystatechange=function (){
if(ajax.readyState==4)
{

if(ajax.status==200)
{
//alert(ajax.responseText);
//var temp = document.getElementById("show");
//temp.value = ajax.responseText;
//temp=null;

}

}
};
ajax.send(null);

}

function ff()
{

creatConnect("http://192.168.8.6:66/test/test.fcg");//请求另一个服务器下的进程,
}
function test1()
{

setInterval("ff()",1000);
}


</script>
</head>
<body onload=test1()>
<input type=text id=show value="fafa">
</body>
</html>

请高手帮忙看看。。。ORZ~~~~~
...全文
173 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
IT_lau 2010-03-01
  • 打赏
  • 举报
回复
这个办法是否可行啊?我试了试好像也是一样没有效果。。。。。
引用 4 楼 muyaoray 的回复:
目前我研究的程度是这样的。

<html>
<head>
<script type="text/javascript">
document.domain="\\192.168.8.6\testF.html";
function creatConnect(urlMsg)
{
var ajax=null;
try{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1)
{
try
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e2)
{
}

}
if(!ajax && typeof XMLHttpRequest != 'undefined'){
ajax = new XMLHttpRequest();
}
if(urlMsg.indexOf("?")>0){
urlMsg += "&randnum=" + Math.random();
}else{
urlMsg += "?randnum=" + Math.random();
}
ajax.open("GET",urlMsg,true);

ajax.onreadystatechange=function (){
  if(ajax.readyState==4)
  {
 
  if(ajax.status==200)
  {
//alert(ajax.responseText);
  //var temp = document.getElementById("show");
  //temp.value = ajax.responseText;
  //temp=null;

  }
 
  }
};
ajax.send(null);

}

function ff()
{
var proxy = document.getElementById("iframeProxy").contentWindow;
proxy.creatConnect("http://192.168.8.6:66/test/test.fcg");//需要请求另一个服务器上的后台fastcgi程序

}
function test1()
{

setInterval("ff()",1000);
}


</script>
</head>
<body onload=test1()>
<input type=text id=show value="fafa">
<iframe src="http://192.168.8.6:66/test/test.fcg" style="display:none;" id="iframeProxy"> </iframe>
</body>
</html>
ami555 2008-11-30
  • 打赏
  • 举报
回复
Ajax是不能直接做跨域访问的!
muyaoray 2008-11-29
  • 打赏
  • 举报
回复
目前我研究的程度是这样的。

<html>
<head>
<script type="text/javascript">
document.domain="\\192.168.8.6\testF.html";
function creatConnect(urlMsg)
{
var ajax=null;
try{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1)
{
try
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e2)
{
}

}
if(!ajax && typeof XMLHttpRequest != 'undefined'){
ajax = new XMLHttpRequest();
}
if(urlMsg.indexOf("?")>0){
urlMsg += "&randnum=" + Math.random();
}else{
urlMsg += "?randnum=" + Math.random();
}
ajax.open("GET",urlMsg,true);

ajax.onreadystatechange=function (){
if(ajax.readyState==4)
{

if(ajax.status==200)
{
//alert(ajax.responseText);
//var temp = document.getElementById("show");
//temp.value = ajax.responseText;
//temp=null;

}

}
};
ajax.send(null);

}

function ff()
{
var proxy = document.getElementById("iframeProxy").contentWindow;
proxy.creatConnect("http://192.168.8.6:66/test/test.fcg");//需要请求另一个服务器上的后台fastcgi程序

}
function test1()
{

setInterval("ff()",1000);
}


</script>
</head>
<body onload=test1()>
<input type=text id=show value="fafa">
<iframe src="http://192.168.8.6:66/test/test.fcg" style="display:none;" id="iframeProxy"></iframe>
</body>
</html>
muyaoray 2008-11-28
  • 打赏
  • 举报
回复
谢谢楼上各位的指点。。。我看看说的网页介绍
cyqlightrain 2008-11-28
  • 打赏
  • 举报
回复
不可以跨域访问的.
如果你非得实现这个效果,就要用System.Net.WebRequest来实现了,(.net)下面的.
peacock 2008-11-28
  • 打赏
  • 举报
回复
Ajax是不能直接做跨域访问的!需要用别的替代方案,请参见:
http://zhengrenchi.blogbus.com/logs/5919334.html
http://blog.sina.com.cn/s/blog_5a010cd10100b1gs.html
http://topic.csdn.net/t/20060126/16/4535837.html

52,797

社区成员

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

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