我是codeigniter的新手,现在因为在重新传递之后将值传递给ajax而陷入困境。我试图在php检查后回显值但是当ajax响应它显示所有整个html元素时,我只想要从PHP回显的值,任何想法请。这是我在控制器中的代码
public function index(){
//Fetch page template
if(isset($_POST['email'])){
$this->data['email'] = $this->sign_up_m->get_by(array('email' => $_POST['email']), TRUE );
if(empty($this->data['email'])){
$this->sign_up_m->save(array('email' => $_POST['email'], 'date' => date('Y-m-d H:i:s')));
}else{
$this->data['email'] = $_POST['email'];
echo'exist';
}
}
$page = $this->uri->segment(1);
if( is_null($page)){
$page = 'home';
}
$this->data['home'] = $this->page_m->get_by(array('nice_name' => $page),TRUE);
count($this->data['home']) || show_404(current_url());
//Fetch page data
$method = '_'. $this->data['home']->template;
if(method_exists($this, $method))
{
$this->$method();
}
else
{
log_message('errors','Could not load template'. $method. 'in file'. __FILE__. 'at line'. __LINE__);
show_error('Could not load template', $method);
}
$this->data['subview'] = $this->data['home']->template;
$this->load->view('_layout_main', $this->data);
}
这是我的ajax
$('.sign_up').click(function(){
var email = $('.email_signup').val();
var validate = isValidEmailAddress(email);
if(!isValidEmailAddress(email)){
$('.invalide_email').css('display','inline');
return;
}
$.ajax({
type: 'post',
url: 'http://localhost:8080/project/www.example.com/',
data: {
email: email,
},
beforeSend: function(){
$('#load').css('display','inline');
},
success: function( response ) {
$('#load').css('display','none');
console.log(response);
}
});
});