【发布时间】:2013-01-30 14:12:25
【问题描述】:
我是 CI 新手,想将 json 编码值传递给查看以进行进一步处理,请参见下文,
jQuery 帖子:
$('#btn_reset_password').click(function(){
var parameters = $('#reset_password_form').serialize();
//alert(parameters);
$.ajax({
url: baseurl + 'site/check_email_exist',
type: 'POST',
data: parameters,
dataType: 'json',
success: function(output_str){
if(output_str.flag == "true"){
// redirect to change password page
window.location.replace(baseurl + 'site/change_user_password');
}else if(output_str == "false"){
$('#result_msg').html("Your email is not in our database");
}else{
$('#result_msg').html(output_str);
}
}
});
});
控制器:
class Site extends CI_Controller {
public function change_user_password() {
$this->load->view('header');
$this->load->view('change_user_password');
$this->load->view('footer');
}
public function check_email_exist(){
$email = $this->input->post('email');
if(!empty($email)){
$query = $this->db->query('SELECT * FROM users WHERE email="'.$email.'"');
if($query->num_rows() > 0){
$row = $query->row();
$output_str = array('email' => $row->email,
'flag' => 'true'
);
//$this->load->view('change_user_password', $output_str);
//$output_str = "true";
}else{
$output_str = "false";
}
}else{
$output_str = "Email cannot leave blank";
}
echo json_encode($output_str);
}
}
查看文件'change_user_password.php':
<?php
//$obj = json_decode($output_str);
echo $email;
?>
<p><div id="result_msg"></div></p>
<p>
<form id="reset_password_form">
<label><b>New Password: </b></label>
<input type="password" name="new_password" style="width:250px;" />
<input type="button" id="btn_change" name="" value="Change" /><br />
</form>
</p>
如何传递/检索数组 $output_str 中的电子邮件值以查看“change_user_password.php”?我尝试了很多方法,但仍然没有解决这个问题,请帮助,非常感谢。
添加:
是不是 Codeigniter 不能接受这种方式的 url 传递参数 => 页面?email=abc@xyz.com?
【问题讨论】:
-
我没有关注这里.. 你想说的是 jquery 与
change_user_password.php的观点不同吗? -
@mamdouh jquery 请求邮件是否返回 true,如果是,将重定向到 change_user_password 视图。
-
而你的
window.location.request()究竟是为了什么..? -
试试我的答案。它应该有帮助
-
codeigniter 使用 url 中的第三个参数作为函数参数见this
标签: json ajax codeigniter