关于Ajax的一个有关问题

关于Ajax的一个问题
问题是这样:我在新入门开始学习Ajax,以下是尝试使用Ajax技术完成一个登录的页面。不知道是不是我的xmlhttp.open()方法里的 url出了问题,还是所谓的“跨域”问题?总之这个代码执行到 if(xmlhttp.readyState==4&&xmlhttp.status==0)是没问题的,然后就不行了。xmlhttp.status==0,无法等于200。这个代码请朋友们帮忙分析一下问题出在哪儿?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
function login(){

var xmlhttp;
           if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


  //var url="http://192.168.1.11:8080/zpapi/ucmembers/onLogin.json?username=540504387@qq.com&password=123456&isuname=2";
  if(xmlhttp!=null){
   
  xmlhttp.open("post","http://192.168.1.11:8080/zpapi/ucmembers/onLogin.json?username=aabb&password=1&isuname=1",true);
   xmlhttp.send(null);
   xmlhttp.onreadystatechange = doResult; 
   
  }
  function doResult(){
    alert(xmlhttp.readyState);//这只是调试使用,测试代码是否运行到了这里
  if(xmlhttp.readyState==4&&xmlhttp.status==0){
  alert(xmlhttp.status);///这也是调试使用,测试代码是否运行到了这里
  
  document.getElementById("main").innerHTML=xmlhttp.responseText;
   }
  }
     
  }

  </script>
</head>

<body>
<form action="login.action">

 username:<input type="text" id="username"/><br/>
 
 password:<input type="password" id="password"/><br/>
 
 <input type="button" value="登录" onclick="login()"/></form>
 <div id="main"></div>
 
</body>
</html>




------解决思路----------------------
0 不是 HTTP 状态码
所以 xmlhttp.status==0 表示的是你在加载本地文件
只要你是从网站上运行的,那么 200 才表示成功完成

如果你的这个程序不是用 http://192.168.1.11:8080/你的程序名 运行的
那么就跨域了!不会正常的

你实际是通过 url 参数传递数据的
使用 post 方式可能引起服务端误解,而不能返回正确的结果

------解决思路----------------------
至少要这样,还要看对方返回的是什么,才囊确定正确的做法<script src='http://192.168.1.11:8080/zpapi/ucmembers/onLogin.json?username=aabb&password=1&isuname=1'></script>

------解决思路----------------------
function GetData() {
            var _ajax = createAjax();
            _ajax.open('get', 'ajax_request.ashx', true);
            _ajax.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
            _ajax.send("name=wcj&time=male");
            _ajax.onreadystatechange = function () {
                if (_ajax.readyState == "4" && _ajax.status == "200") {
                    var _data = _ajax.responseText;
                    document.getElementById("textarea").innerHTML = _data;
                } else {
                    document.getElementById("textarea").innerHTML = "Something wrong with ajax !";
                }
            }
        }
------解决思路----------------------
引用:
0 不是 HTTP 状态码
所以 xmlhttp.status==0 表示的是你在加载本地文件
只要你是从网站上运行的,那么 200 才表示成功完成

如果你的这个程序不是用 http://192.168.1.11:8080/你的程序名 运行的
那么就跨域了!不会正常的

你实际是通过 url 参数传递数据的
使用 post 方式可能引起服务端误解,而不能返回正确的结果
+1