Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter和ajax问题_Php_Ajax_Codeigniter - Fatal编程技术网

Php CodeIgniter和ajax问题

Php CodeIgniter和ajax问题,php,ajax,codeigniter,Php,Ajax,Codeigniter,早上好 在过去的4天里,我一直在绞尽脑汁和眼睛,我不明白为什么这不起作用。基本上,它是一个简单的密码更改脚本,在没有ajax的情况下可以完美运行。但当我用ajax将其分层时,它似乎无法识别,我也不明白为什么。也许你们中的一个伟大的技术人员可以给我指路 我只是想确认一下。它似乎没有组织这是一个ajax请求,只是在每次按下submit按钮时不断重新加载页面 那么形式呢 <form action="<?php echo site_url('site/new_password'); ?>

早上好

在过去的4天里,我一直在绞尽脑汁和眼睛,我不明白为什么这不起作用。基本上,它是一个简单的密码更改脚本,在没有ajax的情况下可以完美运行。但当我用ajax将其分层时,它似乎无法识别,我也不明白为什么。也许你们中的一个伟大的技术人员可以给我指路

我只是想确认一下。它似乎没有组织这是一个ajax请求,只是在每次按下submit按钮时不断重新加载页面

那么形式呢

<form action="<?php echo site_url('site/new_password'); ?>" method="post" class="box validate" id="change_password_form">

    <div class="header">
        <h2>Change Password</h2>
    </div>

    <div class="content">

        <?php if (isset($no_match)) {?>
        <div class="alert error closeEverywhere">
            <span class="icon"></span>
            <strong>Error !</strong>&nbsp;&nbsp;Passwords don't match!
        </div>
        <?php } ?>
        <?php if (isset($changed)) {?>
        <div class="alert success closeEverywhere">
            <span class="icon"></span>
            <strong>Success !</strong>&nbsp;&nbsp;Password was successfully changed
        </div>
        <?php } ?>
        <div class="alert error closeEverywhere" id="alertMessage">
            <span class="icon"></span>
            <strong>Error !</strong>&nbsp;&nbsp;Password don't match!
        </div>
        <div class="alert success closeEverywhere" id="successMessage">
            <span class="icon"></span>
            <strong>Success !</strong>&nbsp;&nbsp;Password was successfully changed
        </div>
        <!-- The form -->
        <div class="form-box">

            <div class="row">
                <label for="change_pw">
                    <strong>Password</strong>
                    <small></small>
                </label>
                <div>
                    <input tabindex=1 type="password" class="required noerror" name="change_pw" id="change_pw" />
                    <?php echo form_error('change_pw','<label class="error" for="change_pw" generated="true">','</label>'); ?>
                </div>
            </div>

            <div class="row">
                <label for="change_pw_conf">
                    <strong>Again</strong>
                    <small>Password Confirmation</small>
                </label>
                <div>
                    <input tabindex=2 type="password" class="required noerror" name="change_pw_conf" id="change_pw_conf" />
                    <?php echo form_error('change_pw_conf','<label class="error" for="change_pw_conf" generated="true">','</label>'); ?>
                </div>
            </div>

        </div><!-- End of .form-box -->

    </div><!-- End of .content -->

    <div class="actions">
        <div class="left">
        </div>
        <div class="right">
            <input tabindex=3 type="submit" value="Change Password" name="change_btn" id="change_btn" />
        </div>
    </div><!-- End of .actions -->

</form>
最后给出了控制器的设计方法

  function new_password()
  {
      if ($this->input->is_ajax_request())  
      {
          $return_arr['status'] = 0;
          echo json_encode($return_arr); // return value 
          exit();
      }

      $this->load->view('site/new_password_view');  
  }

我是否缺少在javascript中定义base_url的位置?如果不是的话,我想这是你的问题,你的代码没有被发送到一个合法的URL。base_url是一个CodeIgniter PHP函数。例如下面这行

$.post(base_url+'site/new_password',$('#change_password_form').serialize(),function(data) {
应改为:

$.post("<?=base_url();?>site/new_password",$('#change_password_form').serialize(),function(data) {
$.post(“站点/新密码”,$(“#更改密码形式”).serialize(),函数(数据){

您看到XHR请求数据和响应数据了吗?您可以使用chorme和FF与FireBug一起完成。这并不是因为没有定义基本Url,而是因为拼写错误。非常感谢您的帮助,并对延迟回复表示歉意
$.post("<?=base_url();?>site/new_password",$('#change_password_form').serialize(),function(data) {