0

私は ajax に関して質問があります。私はそれに慣れていないので、最適な手順がわかりません。とにかく、CodeIgniter アプリに ajax を組み込みましたが、2 つの異なる応答の可能性があり、ajax でこれを処理する方法がよくわかりません。

結果を div に追加する代わりに、URL を更新することはできませんか?

私のコントローラーにはフォーム検証があります.falseの場合は更新してエラーを表示したいのですが、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);
}
4

2 に答える 2

1

ページをリロードしたい場合は、次のことができます。

$.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function(data) {
            location.reload();       
        }
    });
于 2012-05-30T12:00:27.443 に答える
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"
);
于 2012-05-30T15:21:13.527 に答える