我之前用的都是windows+iis跑php,现在转到了linux+apache,却发现原来主页上很多js调用都失效了,必须要把js内容写在首页里面才能正常使用。但是还有一个ajax却依旧无法工作,写在主页中也没用,提示无权限这个ajax是远程调用别的网站的一个页面的内容的var texthttp = null;var isIE = null;var TextDoc = null;var parser = null;var oSerializer = null;
if (window.ActiveXObject)
{
    try
    {
        texthttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e)
    {
        texthttp = new ActiveXObject("MsXml2.XMLHTTP");
    }
}
else
{
    texthttp = new XMLHttpRequest();
    isIE = false;
}function OpenFile(fName)
{
    if(texthttp.readyState == 4 || texthttp.readyState == 0)
    {
        texthttp.open("GET",fName,true);
        texthttp.onreadystatechange = fileonreadystatechange ;
        //texthttp.send();
texthttp.send(null); 
    }
    
}
function fileonreadystatechange()
{
    if (texthttp.readyState == 4)
    {
        TextDoc = texthttp.responseText;
        ///alert(TextDoc);
        document.getElementById('infodiv').innerHTML=texthttp.responseText;
    }
    else
    {
document.getElementById("infodiv").innerHTML="<img src='/images/loading.gif' /> Loading ...";
    }
}
OpenFile("http://www.sohu.com/");

解决方案 »

  1.   

    还有以下这段代码,是asp的,如果修改成php的,应该怎么写啊?Dim Url,Str
    Dim Body,S,O
    Url="http://www.sohu.com"

    Function PostData(PostUrl,PostMode)
    Dim Http
    Set Http = Server.CreateObject("msxml2.XMLHTTP")
    With Http
    .Open "POST",PostUrl,False
    .SetRequestHeader "Content-Length",Len(PostStr)
    .SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
    .SetRequestHeader "Referer",PostUrl
    .Send PostStr
    If PostMode=0 Then
    PostData = .ResponseBody
    Else
    PostData = BytesToBstr(.ResponseBody,"gb2312")
    End If
    End With
    Set Http = Nothing
    End Function
    Function BytesToBstr(Body,Cset)
    Dim ADOS
    Set ADOS = Server.CreateObject("Adodb.Stream")
    With ADOS
    .Type = 1
    .Mode =3
    .Open
    .Write Body
    .Position = 0
    .Type = 2
             .Charset = Cset
    BytesToBstr = .ReadText 
    .Close
    End With
    Set ADOS = Nothing
    End FunctionResponse.Write("·"&body)'输出
      

  2.   

    XMLHTTP 无论在什么系统中都不能实现web方式的跨域操作
      

  3.   

    ajax跟是不是linux是没有什么关系的
      

  4.   

    你的第二问可以用
    curl
    sock
    file_get_contents
    com+xmlhttp (只限Windows环境)
    实现,现成的代码很多。无需套改asp
      

  5.   

    明白了那有没有php的网页小偷?我不想干坏事,呵呵,是取自己另外一个网站的页面内容