2013-01-02 4 views
0

아침, 내가 지난 4 일 동안 내 머리와 눈을 건 드리는 된이 밤은 작동 왜 볼 수없는CodeIgniter의 및 아약스 문제

. 기본적으로 간단한 암호 변경 스크립트이며 아약스없이 완벽하게 실행됩니다. 하지만 아약스로 레이어를 만들면 그것을 인식하지 못하고 왜 볼 수 없게됩니다. 어쩌면 당신 중 한 사람이 저에게 그 길을 보여줄 수 있습니다.

확인하셔야합니다. 그것은 아약스 요청임을 구성하고 단지 페이지를 I 버튼

그래서 폼

<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> 

그리고 AJAX의 장에게 제출 누를 때마다 다시로드 유지하지 보인다

$(document).ready(function() { 
$('#login_form').on('submit',function() { 

    $.post(base_url+'site/login',$('#login_form').serialize(),function(data) { 
     if(!data || data.status !=1) 
     { 
      showError(); 
      return false; 
     } 
     setTimeout("window.location.href='"+base_url+"site/new_password'", 1000); 

    },'json'); 
    return false; 
}); 

$('#change_password_form').on('submit',function() { 

     $.post(base_url+'site/new_password',$('#change_password_form').serialize(),function(data) { 
     if(!data || data.status !=1) 
     { 
      showError(); 
      return false; 
     } 
     alert('Success'); 
     showSuccess(); 
     setTimeout("window.location.href='"+base_url+"member_section'", 1000); 

    },'json'); 
    return false; 
}); 

function showError() { 
    $('#alertMessage').slideDown(500); 
} 

function showSuccess() { 
    $('#successMessage').slideDown(500); 
} 
}); 

마지막으로 컨트롤러 방법

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'); 
    } 
+0

유는 XHR 요청 데이터와 응답 데이터를 보았는가? U는 firebug와 함께 chorme와 FF를 사용하여 그것을 할 수있다. – casper123

답변

1

당신은 자바 스크립트에서 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) { 
+0

그것은 Base_Url이 정의되지 않았던 많은 것이 아니었고, 그것은 단지 missspelled였다. 늦게 답장을 보내 주셔서 감사 드리며 사과드립니다. –