2013-12-19 44 views
1

我想在Codeigniter中使用jQuery ajax。在以前的項目中,我已經使用jQuery ajax,但這次我遇到了問題。以下是我的代碼jquery Ajax在codeigniter

$.ajax({ 
    type:"POST", 
    url:"<?php echo base_url()?>register", 
    data:{ 
    name:$("#f_name").val() 
    }, 
    cache:false, 
    success:function(result){ 
    $("#registration_result").html(result);     
    alert("success"); 
    }, 
    error:function(){ 
    alert("fail"); 
    } 
}); 

這裏的問題是,我沒有得到錯誤信息「失敗」。請讓我知道如果我在這裏做錯了什麼。

+0

你有控制檯的任何錯誤?如果是這樣,然後plz分享。在js中使用php標籤或代碼不是一種好的做法。 – sas

+0

@crack:我得到這個錯誤「MOCK POST:http:// localhost/ClickMyStay/register Object {url:」http:// localhost/ClickMyStay/register「,isLocal:false,global:true,type:」 POST「,contentType:」application/x-www-form-urlencoded; charset = UTF-8「...}」 –

+0

嘿,我發現這在一個js文件中。 $ .extend({ajax:handleAjax}); 我刪除它,它的工作很好...! –

回答

0

請檢查您的註冊頁面的URL,也許是頁面沒有找到, 所以阿賈克斯陷入誤差函數,

error:function(){ 
    alert("<?php echo base_url()?>register"); 
    alert("fail"); 
    } 

當你的Ajax運行它會提醒「網址註冊」,那麼請打開url來檢查頁面是否存在。

如果寄存器頁是不存在的,

  • 確保寄存器控制器是存在的「index_page」 的application/config/config.php文件

  • 校驗值$ config ['index_page'] ='index.php';

如果該值 「的index.php」,改變你的Ajax的網址爲

url:"<?php echo base_url()?>index.php/register",