-2

I am sending post request via ajax to controller/function and getting back result in success: and it loads result on same page as it does always, but I want to quit ajax when I reach at controller/function, because I want to load different view there $this->load->view('htmlfile').

function test() {

    var wingId = $('#wing_id').val();
    var classId = $('#class_id').val();
    var sectionId = $('#section_id').val();
    var gender = $('#gender').val();        

    $('#error').hide();

    $.ajax({
        url: "<?php echo base_url()?>admin/library/totalStudentsReportPrint/",

        data: {

            wingId: wingId,
            classId: classId,
            sectionId: sectionId,
            gender: gender

        },
        type: "post",

        success: function (result) {
            $('#data_result').html(result);

        }
    });

}

Php Controller function

function totalStudentsReportPrint(){

    $student_data['wingId'] = $_POST['wingId'];
    $student_data['classId'] = $_POST['classId'];
    $student_data['sectionId'] = $_POST['sectionId'];
    $student_data['gender'] = $_POST['gender'];          


 $this->load->view('institute/admin/library/total_students_btm_tbl_print',$student_data);
}
mohsin
  • 594
  • 2
  • 8
  • 29
  • i dont understand your problem? You want to load other template? Why you dont send template path via ajax and check the $_POST value inside the function? – kaito Mar 08 '16 at 10:03

1 Answers1

0

All you want is to abort the $.ajax call, right? take a look to Abort Ajax requests using jQuery for the answer.

However, you cannot abort it from PHP. The $.ajax is running in your client browser, not in your PHP server. And the $.ajax call runs PHP in a separate thread, vs the PHP which loads your view. All you can eventually do is when you want to load a new view, you certainly have an action on the browser made by the client. Before sending the request to your PHP server, you may want to abort the $.ajax call first. Another way is to have a PHP shared memory variable, that you set when loading the view, and implement your $.ajax PHP call handler suck a way that you stop processing if that variable is set for that session. A bit complicated vs simply let it go.

Community
  • 1
  • 1
cyrille
  • 2,616
  • 1
  • 10
  • 18