Welcome Guest, Not a member yet? Register   Sign In
ajax call on success redirect page from controller loaded in place of form
#4

[eluser]axmed[/eluser]
this problem driving me mad since i know so little about ajax, i tried using http headers and nothing ajax continued to ignore the redirect and load it in the div, so i tried what PhilTem said, is this the correct way to do it? will it be supported by browsers or cause any error.
here is the fix:

jquery

Code:
$("form.user_form").live("submit",function(event) {
      event.preventDefault();
      $("#loader").removeClass('hidden');
      $.ajax({
          type: $(this).attr('method'),
          url: $(this).attr('action'),
          cache: false,
          dataType:"html",
          data: $(this).serialize(),
          success: function(data) {
              var res = $(data).filter('span.redirect');
              if($(res).html() != null){
                  [removed].href=$(res).html(); //window./location./href could not post so ignore /
                  return false;
              }
              $("#center").html(data);
          },
          error: function() {

          }
      })

   return false;
  });


and in the Controller

Code:
function _show_message($message, $state = true, $redirect ='')
{
        if($state)
        {
            $data = '<div id="notification" class="success"><strong>'.$message.'</strong></div>';
        }else{
            $data = '<div id="notification" class="bug"><strong>'.$message.'</strong></div>';
        }
$this->session->set_flashdata('note', $data);
        if ( !$this->input->is_ajax_request())
        {
            redirect(base_url().$redirect,'location',302);
        }
        else
        {
             echo '<span class="redirect">'.base_url().$redirect.'</span>';
        }

}


Messages In This Thread
ajax call on success redirect page from controller loaded in place of form - by El Forum - 02-06-2012, 09:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB