2012-05-30 29 views
0

我有一個關於ajax的問題​​,我對它很陌生,所以不確定最好的程序。無論如何,我已經將ajax加入到我的CodeIgniter應用程序中,但我有兩種不同的響應,我不太清楚如何在我的ajax中處理這個問題。ajax響應刷新url而不是追加?

而不是將我的結果追加到一個div可以不只是刷新網址?

在我的控制器中我有表單驗證,當它是假我想刷新顯示我的錯誤,但如果它返回true我想顯示新的頁面,如果這是有道理的?

視圖

$.post("<?php echo base_url(); ?>part-one", 
    $("form").serialize(), 
    function(result){ 
     // if errors show this 
     $("#error").html(result); 

     // if there are no errors how do I check the response to refresh the page to a new url? 
    }, "html" 
); 

控制器

if($this->form_validation->run() == FALSE){ 
    $data['content'] = "part_one"; 
    $this->load->view('template', $data); 
} else { 
    $data['content'] = "part_two"; 
    $this->load->view('template', $data); 
} 

回答

0

如果我理解你的權利那麼這段代碼可以幫助你......

$.post("<?php echo base_url(); ?>part-one", 
    $("form").serialize(), 
    function(result){ 
     // if errors show this 
     $("#error").html(result); 
if(result =='false condition response') 
{ 
    window.location.reload() 
} 
if(result == 'True Conditon response') 
{ 
window.location.href('URL of the page') 
} 


    // if there are no errors how do I check the response to refresh the page to a new url? 
    }, "html" 
); 
1

如果要重新加載,你可以做的頁面;

$.ajax({ 
     url: url, 
     type: 'post', 
     data: data, 
     success: function(data) { 
      location.reload();  
     } 
    });