huboo82
发表于 2012-3-2 13:56:04
在firebug里看你那个post的链接发送的是post的请求么。
pspman2
发表于 2012-3-2 13:57:06
huboo82 发表于 2012-3-2 13:50 static/image/common/back.gif
直接看看这个链接是什么内容吧
http://localhost/codeigniter/index.php/index/usercheck
huboo82
发表于 2012-3-2 13:59:00
pspman2 发表于 2012-3-2 13:57 static/image/common/back.gif
http://localhost/codeigniter/index.php/index/usercheck
在浏览器打开这个链接,我记得好像有人说过controller的名字不能用index,你把你的index的controller改个其他名字试试看吧。刚才那个console.log出来的东西好像是被转向了。
pspman2
发表于 2012-3-2 14:11:27
huboo82 发表于 2012-3-2 13:59 static/image/common/back.gif
在浏览器打开这个链接,我记得好像有人说过controller的名字不能用index,你把你的index的controller改个 ...
改了也一样,我把jq的代码全发上去吧,请你看看<!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>
<base href="<?php echo base_url() ?>" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen, projection" />
<script src="js/jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
var $div_li =$("div.tab_menu ul li");
$div_li.click(function(){
window.location.href="http://baidu.com/"+$(this).html()
})
$div_li.mouseover(function(){
$(this).addClass("selected") //当前<li>元素高亮
.siblings().removeClass("selected");//去掉其它同辈<li>元素的高亮
var index =$div_li.index(this);// 获取当前点击的<li>元素 在 全部li元素中的索引。
$show = $("div.tab_box > div"); //选取子节点。不选取子节点的话,会引起错误。如果里面还有div
$show.eq(index).fadeIn(500) //显示 <li>元素对应的<div>元素
.siblings().hide();
//隐藏其它几个同辈的<div>元素
}).hover(function(){
$(this).addClass("hover");
},function(){
$(this).removeClass("hover");
})
//----------用户验证-----------------------------------------------------
$('#zhuce').click(function(){
var bh = $("body").height();
var bw = $("body").width();
$("#fullbg").css({
height:bh,
width:bw,
display:"block"
});
$('.message').show();
//如果是必填的,则加红星标识.
$("form :input.required").each(function(){
var $required = $("<span class='high'> *</span>"); //创建元素
$(this).parent().append($required); //然后将它追加到文档中
});
//文本框失去焦点后
$('form :input').blur(function(){
var $parent = $(this).parent();
$parent.find(".formtips").remove();
//验证用户名
if( $(this).is('#user_name') ){
if( this.value=="" || this.value.length < 6 ){
$parent.append('<span class="formtips onError"></span>');
}else{
$.ajax({
type: "post",
url: "<?php echo site_url('show/usercheck') ?>",
datatype: "text",
data:"name="+$("#user_name").val(),
success: function(data){
console.log(data);
if(data=="2"){
message='hello';
$append = '<span class="formtips onSuccess">'+message+'</span>';
$parent.append($append);
}else{
$parent.append('<span class="formtips onError">'+data+'</span>');
}
}
});
}
}
//验证密码
if( $(this).is('#user_password') ){
if( this.value=="" ){
$parent.append('<span class="formtips onError"></span>');
}else{
$parent.append('<span class="formtips onSuccess"></span>');
}
}
//验证邮件
if( $(this).is('#email') ){
if( this.value=="" || ( this.value!="" && !/.+@.+\.{2,4}$/.test(this.value) ) ){
$parent.append('<span class="formtips onError"></span>');
}else{
$parent.append('<span class="formtips onSuccess"></span>');
}
}
})
/*.keyup(function(){
$(this).triggerHandler("blur");
}).focus(function(){
$(this).triggerHandler("blur");
});//end blur
*/
//提交,最终验证。
$('#send').click(function(){
$("form :input.required").trigger('blur');
var numError = $('form .onError').length;
if(numError){
return false;
}
});
//重置
$('#res').click(function(){
$(".formtips").remove();
})
$('#close').click(function(){
$('form :input.required + span').remove();
$('.message,#fullbg').hide();
})
})
//移动
$("#gb").mousedown(function(e){
var offset = $(".message").offset();
var p = {top:offset.top - e.clientY,left:offset.left - e.clientX};
if (!e) e = window.event;
$(document).mousemove(function(e){
$("#gb").css("cursor","text");
$(".message").css({"top":e.clientY + p.top,"left":e.clientX + p.left,"position":"absolute"});
});
$(document).mouseup(function(){
$("#gb").css("cursor","move");
$(".message").css("position","fixed !important");
$(this).unbind("mousemove");
});
});
})
</script>
</head>
<body>
<div id="fullbg"></div>
<div class="message"><div class='sharp color6'><b class='b1'></b><b class='b2'></b><b class='b3'></b><b class='b4'></b><div class='content'><div style='text-align:right; cursor:move;' id='gb'><span style="cursor:pointer;" id='close'>关闭</span></div><div id='login' class='login'>用户注册</div><div style=' border:1px solid #999; width:190px;'></div><form action="<?php echo site_url('index/add/'); ?>" method='post'><ul><li><label for='user_name'>用户名:</label><input type='text' name='name' id='user_name' size='20' class='required' /></li><li><label for='user_password'>密码:</label><input type='password' name='password' id='user_password' size='20' class='required' /></li><li><label for='email'>邮箱:</label><input type='text' id='email' name='email'size='20' class='required' /></li><li id='sub'><br /><input type='submit' name='submit' id='send' class='bottom' value='提交' /><input type='reset' id='res' class='bottom' value='重置'/></li></ul></form></div><b class='b5'></b><b class='b6'></b><b class='b7'></b><b class='b8'></b></div></div>
<div id="head">
<div class="title">在线视频</div>
<div class="search">
<div style=" clear:both; margin-left:32px;"><form id="form1" name="form1" method="post" action="">
<ul><li><input name="search" id="search" type="text" size="21" maxlength="20" /></li><li> <select name="movie_type" >
<option value="全部" selected >全部</option>
<option value="电影">电影</option>
<option value="动漫">动漫</option>
</select></li><li> <input type="submit" name="submit"value=" "style="width:57px; height:24px; cursor:pointer; border:none; background-image:url(image/ico00000.gif)";/></li></ul>
</form>
</div>
</div>
</div>
<div class="main">
<!--左边框-->
<div class="left">
<?php
if($this->session->userdata('user_data')){
$this->load->view('login_ok_view');
}else{
$this->load->view('login_view');
}
?>
</div>
pspman2
发表于 2012-3-2 14:15:17
huboo82 发表于 2012-3-2 13:56 static/image/common/back.gif
在firebug里看你那个post的链接发送的是post的请求么。
是post的
http://codeigniter.org.cn/forums/data/attachment/album/201203/02/1414370w8wv38yiys0y58m.jpg
huboo82
发表于 2012-3-2 14:15:37
直接访问你的
<?php echo site_url('show/usercheck') ?>
链接应该在页面里显示一个2,所以如果这个链接访问都不正确的话,后面的脚本判断就无从谈起,基本的东西要先确认了。链接能不能访问,结果是否符合控制器里的逻辑等等。
huboo82
发表于 2012-3-2 14:16:39
本帖最后由 huboo82 于 2012-3-2 14:19 编辑
pspman2 发表于 2012-3-2 14:15 static/image/common/back.gif
是post的
你这个post返回的东西明显是有问题的,那个2上面有一个空行。确认一下没有用bom和其他不必要的输出,也检查一下你的模型方法里是否有echo或其他输出的东西。
huboo82
发表于 2012-3-2 14:25:52
我看了你之前的帖子,所以最好你还是再审视一遍自己的代码,毕竟我们看不到它,只能凭你的反馈来帮你解决问题。
pspman2
发表于 2012-3-2 14:28:52
huboo82 发表于 2012-3-2 14:16 static/image/common/back.gif
你这个post返回的东西明显是有问题的,那个2上面有一个空行。确认一下没有用bom和其他不必要的输出,也检 ...
嗯,好像是有个空行,那个,能请问一下怎么去掉那个bom吗,我知道用utf-8编码难免会遇到这问题,我把这个控制器的代码也贴上,请你看看
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
header("Content-Type: text/html;charset=utf-8");
class Show extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->Model('Index_model');
}
public function index()
{
if($this->session->userdata('user_data')){
$data['query']=$this->Index_model->login_check();
$this->load->view('index_header_view',$data);
$this->load->view('index_main_view');
$this->load->view('footer_view');
}else{
$this->load->view('index_header_view');
$this->load->view('index_main_view');
$this->load->view('footer_view');
}
}
function check(){
if($this->Index_model->login_check()){
redirect('index');
}else{
$src=site_url('index');
echo "<script language=javascript>alert('登录失败');window.location.href='".$src."'</script>";
}
}
function usercheck(){
if($this->Index_model->user_check()){
echo "该用户已存在";
exit;
}else{
echo "2";
exit;
}
}
function add(){
if($this->Index_model->user_add()){
$session['name']=$this->input->post('name');
$session['face']='defult.jpg';
$session['email']=$this->input->post('email');
$session['user_data']=true;
$this->session->set_userdata($session);
$src=site_url('index');
echo "<script language=javascript>alert('注册成功');window.location.href='".$src."'</script>";
}else{
echo '注册失败';
}
}
function logout(){
$this->session->sess_destroy();
redirect('index');
}
function face_upload(){
$config['upload_path'] = './upload/face/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width']= '1024';
$config['max_height']= '768';
$config['file_name']= $this->session->userdata('name');
$config['overwrite']= TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
//$error['query']=$this->Index_model->login_check();
//$this->load->view('index_view', $error);
}
else
{
$img_message=$this->upload->data();
$img=$img_message['file_name'];
$this->Index_model->user_face_update($img);
redirect('index');
//echo $img;
}
}
function password(){
if(!$this->Index_model->user_password_update()){
echo '原密码不对';
}else{
echo '修改成功';
}
}
}
pspman2
发表于 2012-3-2 14:33:33
huboo82 发表于 2012-3-2 14:15 static/image/common/back.gif
直接访问你的
链接应该在页面里显示一个2,所以如果这个链接访问都不正确的话,后面的脚本判断就无从谈起 ...
输出的结果是“该用户已存在”,又雾水了,刚接ci不久,问题有点多,请不要见怪,也十分感谢你的回答