请教各位大侠,我的这段代码为什么在opera浏览器里执行到alert(“s”)处就再也执行不下去了呢?在IE里可以,在opera和firefox浏览器里就不行,希望各位帮助指点。谢谢。
<script type="text/javascript">
$(function()
{
var xhr = new AjaxXmlHttpRequest();
$("#btnAjax").click(function(event)
{
var userNameNew = document.getElementById("UserName").value;
var password = document.getElementById("PWD").value;
var xhr = new AjaxXmlHttpRequest();
alert("s");
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
document.getElementById("divResult").innerHTML = xhr.responseText;
alert(xhr.responseText);
}
}
xhr.open("Get","http://www.163.com",false,userNameNew,password);
xhr.send(null);
}
)
}
)

解决方案 »

  1.   

    var xhr = new AjaxXmlHttpRequest(); // 这个类是哪来的?也许只有IE里有
    Ajax的是XmlHttpRequest。
    既然已经使用了jQuery,为什么不直接使用$.get(), $.post(), $.ajax() ?
      

  2.   


    //跨浏览器获得xmlhttprequest对象
    function AjaxXmlHttpRequest()
    {
    var xmlHttp;
    try
    {
    //FIREFOX
    xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
    //IE
    try
    {
    xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
    try
    {
    xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e)
    {
    alert("您浏览器不支持ajax!");
    return false;
    }
    }
    }
    return xmlHttp;
    }这是那个request,不过希望楼上的指教一下jquery如何来处理这样的问题呢?谢谢。
      

  3.   

    看一下文档,特别简单好用$.post("server/request_questions.php", {categoryId: categoryId}, 
        function(result) {
            // 处理服务器返回来的参数
        });
      

  4.   

    我要实现这样一个功能:我现在要从***.com 登录到 ***.com:8080页面,需要在.com传入用户名和密码后点击登录按钮到.com:8080页面;现在就是这个需求。