用户
 找回密码
 入住 CI 中国社区
搜索
查看: 7517|回复: 15
收起左侧

[讨论/交流] CI框架实现ajax的路径问题

  [复制链接]
发表于 2012-6-16 11:12:28 | 显示全部楼层 |阅读模式
<script type="text/javascript">
var xmlHttp;

function GetXmlHttpObject()
{
  var xmlHttp=null;
    try
     {
           // Firefox,chrome,Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
       }
    catch (e)
     {
          //Internet Explorer
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");     
       }
     catch (e)
       {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
return xmlHttp;
}
function go(names){
           var xmlHttp=GetXmlHttpObject();   //创建浏览器对象
           if (xmlHttp==null)
            {
              alert ("Browser does not support HTTP Request");
              return;
             }

       
var url="<?=site_url()?>/login/ajax";//主要是这个路径问题
//var url="http:localhost/CodeIgniter/index.php/login/ajax  绝对路径也不行
url=url+"?user="+names;
xmlHttp.open("Get",url,true);
xmlHttp.onreadystatechange = function () {       
       
    if (xmlHttp.readyState == 4 ) {
           
            document.getElementById("result").innerHTML = xmlHttp.responseText;
         
    }
}  
xmlHttp.send(null);



}
</script>
</head>
<body>
<h2><?php echo $frist ?></h2>
<div style="color: red;"><?php if(isset($error)) echo $error;?></div>
<form action="zhi" method="post" enctype="multipart/form-data" >
       <table>
              <tr>
                  <td>用户名:</td>
                  <td><input type="text" name="user" value="<?php echo set_value('user')?>" size="20" onblur="go(this.value)" /><?php echo form_error('user')?></td>
                  <td><div style="color: red;" id="result">11</div> </td>            
              </tr>
              <tr>
                  <td>密 码:</td><td><input type="password" name="password"  size="20" /><?php echo form_error('password')?></td>
              </tr>
                <tr>
                  <td>确认密 码:</td><td><input type="password" name="password2"  size="20" /><?php echo form_error('password2')?></td>
              </tr>
              <tr>
                  <td><input type=submit value="注册"/></td>
              </tr>
       </table>
    </form>


</body>
</html>
总是报那个路径找不到,不知道什么原因写绝对路径也不行,也是一样的报警?404 Page Not Found
The page you requested was not found.
发表于 2012-6-16 12:28:22 | 显示全部楼层
建议你使用CI的第三方类库cjax
 楼主| 发表于 2012-6-16 16:04:30 | 显示全部楼层
多谢了!
发表于 2012-6-16 17:12:11 | 显示全部楼层
JQ的吗?
发表于 2012-6-17 12:57:19 | 显示全部楼层
//var url="http:localhost/CodeIgniter/index.php/login/ajax  绝对路径也不行
//var url="http//:localhost/CodeIgniter/index.php/login/ajax  绝对路径也不行

xmlHttp.open("Get",url,true);
ci的get方式开启了吗?
发表于 2012-6-17 22:19:03 | 显示全部楼层
var url="<?=site_url()?>/login/ajax";//主要是这个路径问题
//var url="http:localhost/CodeIgniter/index.php/login/ajax  绝对路径也不行
--------------------------------------------------
var url="<?=site_url('login/ajax')?>/";
//var url="http://localhost/CodeIgniter/index.php/login/ajax/

这样子试试
 楼主| 发表于 2012-6-19 10:10:19 | 显示全部楼层
yunnysunny 发表于 2012-6-17 12:57
//var url="http:localhost/CodeIgniter/index.php/login/ajax  绝对路径也不行
//var url="http//:localho ...

GET方式开启了
 楼主| 发表于 2012-6-19 10:11:46 | 显示全部楼层
kjzwj 发表于 2012-6-17 22:19
var url="/login/ajax";//主要是这个路径问题
//var url="http:localhost/CodeIgniter/index.php/login/aja ...

var url="<?=sit_url('login/ajax')?>/";
这样也不行
发表于 2012-6-19 14:23:31 | 显示全部楼层
把地址拷贝到地址栏能打开吗?
 楼主| 发表于 2012-6-20 10:13:01 | 显示全部楼层
yunnysunny 发表于 2012-6-19 14:23
把地址拷贝到地址栏能打开吗?

不行

本版积分规则