2016-11-17 2 views
0
function open_appointment(id) 
{ 
save_method = 'open_appointment'; 
$('#form_open_appointment')[0].reset(); // reset form on modals 
$('.form-group').removeClass('has-error'); // clear error class 
$('.help-block').empty(); // clear error string 

//Ajax Load data from ajax 
$.ajax({ 
    url : "<?php echo site_url('ReceptionistController/ajax_edit_appointment')?>/" + id, 
    type: "GET", 
    dataType: "JSON", 
    success: function(data) 
    { 

     $.ajax({ 
      url : "<?php echo site_url('ReceptionistController/ajax_edit_patient')?>/" +data.ap_patient, 
      type: "GET", 
      dataType: "JSON", 
      success: function(data) 
      { 

       $('[name="pt_id"]').val(data.pt_id); 
       $('[name="pt_name"]').val(data.pt_name); 
       $('[name="pt_dob"]').val(data.pt_dob); 
       $('[name="pt_sex"]').val(data.pt_sex); 
       $('[name="pt_contact"]').val(data.pt_contact); 
       $('[name="pt_email"]').val(data.pt_email); 
       $('[name="pt_address"]').val(data.pt_address); 
       id=parseInt(id); 
       var next_id=id+1; 
       var previous_id=id-1; 
       //button to call back the function with next id 
       $('#next_patient').click(function() { 
       alert("next"+next_id); 
       open_appointment(next_id); 
       }); 
       //button to call back the function with previous id 
       $('#previous_patient').click(function() { 
       alert("next"+next_id); 
       open_appointment(previous_id); 
       }); 

      }, 
      error: function (jqXHR, textStatus, errorThrown) 
      { 
       alert('Failed'); 

      } 
     }); 

     $('#modal_open_appointment').modal('show'); // show bootstrap modal when complete loaded 
     $('.modal-title').text('Open Appointment'); // Set title to Bootstrap modal title 

    }, 
    error: function (jqXHR, textStatus, errorThrown) 
    { 
     alert('Error get data from ajax'); 
    } 
    }); 
} 

Bei Klick auf Weiter-Taste arbeitet die Funktion mit dem nächsten id (sagen id 1) Aber das Problem ist auf zweiten Mal Klicken der nächsten Taste die Funktion Last zwei Mal (mit Strom geladen wird ID und mit der nächsten ID sagen ID 1 und 2) und für den dritten Klick laden sie dreimal (load id say id 1 id 2 und id 3). ich will es nur die letzte id auf jeder sein klickenAjax-Aufruf nicht mit Onclick

+0

Ereignis Call-Stack in Funktion (klick) Ich denke, –

Antwort

2

versuchen

var next_id=1; 
var previous_id=1; 
function open_appointment(id) 
{ 
save_method = 'open_appointment'; 
$('#form_open_appointment')[0].reset(); // reset form on modals 
$('.form-group').removeClass('has-error'); // clear error class 
$('.help-block').empty(); // clear error string 

//Ajax Load data from ajax 
$.ajax({ 
    url : "<?php echo site_url('ReceptionistController/ajax_edit_appointment')?>/" + id, 
    type: "GET", 
    dataType: "JSON", 
    success: function(data) 
    { 

     $.ajax({ 
      url : "<?php echo site_url('ReceptionistController/ajax_edit_patient')?>/" +data.ap_patient, 
      type: "GET", 
      dataType: "JSON", 
      success: function(data) 
      { 

       $('[name="pt_id"]').val(data.pt_id); 
       $('[name="pt_name"]').val(data.pt_name); 
       $('[name="pt_dob"]').val(data.pt_dob); 
       $('[name="pt_sex"]').val(data.pt_sex); 
       $('[name="pt_contact"]').val(data.pt_contact); 
       $('[name="pt_email"]').val(data.pt_email); 
       $('[name="pt_address"]').val(data.pt_address); 
       id=parseInt(id); 
       next_id=id+1; 
       previous_id=id-1; 
      }, 
      error: function (jqXHR, textStatus, errorThrown) 
      { 
       alert('Failed'); 

      } 
     }); 

     $('#modal_open_appointment').modal('show'); // show bootstrap modal when complete loaded 
     $('.modal-title').text('Open Appointment'); // Set title to Bootstrap modal title 

    }, 
    error: function (jqXHR, textStatus, errorThrown) 
    { 
     alert('Error get data from ajax'); 
    } 
    }); 
} 



$(document).on('click','#next_patient',function() { 
    alert("next="+next_id); 
    open_appointment(next_id); 
}); 
//button to call back the function with previous id 
$(document).on('click','#previous_patient',function() { 
    alert("previous="+previous_id); 
    open_appointment(previous_id); 
}); 
+0

seine Arbeit gut, danke next_id der "1 + id". :) Danke – kashif

+0

@kashif froh, Ihnen zu helfen :) :) –

0

Ich denke, Sie sollten rufen .unbind(), bevor Sie Ereignis Tasten binden klicken.

$('#next_patient').unbind().bind('click', function() { 
    alert("next"+next_id); 
    ... 
}) 
0

function open_appointment(id) 
 
{ 
 
save_method = 'open_appointment'; 
 
$('#form_open_appointment')[0].reset(); // reset form on modals 
 
$('.form-group').removeClass('has-error'); // clear error class 
 
$('.help-block').empty(); // clear error string 
 

 
//Ajax Load data from ajax 
 
$.ajax({ 
 
    url : "<?php echo site_url('ReceptionistController/ajax_edit_appointment')?>/" + id, 
 
    type: "GET", 
 
    dataType: "JSON", 
 
    success: function(data) 
 
    { 
 
     $.ajax({ 
 
      url : "<?php echo site_url('ReceptionistController/ajax_edit_patient')?>/" +data.ap_patient, 
 
      type: "GET", 
 
      dataType: "JSON", 
 
      success: function(data) 
 
      { 
 
       $('[name="pt_id"]').val(data.pt_id); 
 
       $('[name="pt_name"]').val(data.pt_name); 
 
       $('[name="pt_dob"]').val(data.pt_dob); 
 
       $('[name="pt_sex"]').val(data.pt_sex); 
 
       $('[name="pt_contact"]').val(data.pt_contact); 
 
       $('[name="pt_email"]').val(data.pt_email); 
 
       $('[name="pt_address"]').val(data.pt_address); 
 
       id=parseInt(id); 
 
       var next_id=id+1; 
 
       var previous_id=id-1; 
 
       
 
       // **************************************** 
 
       // move out 2 event out function 
 
       // set value next_id & prev_id to html tag 
 
    
 
       $('#next_patient').attr('data-next',next_id); 
 
       $('#previous_patient').attr('data-prev',previous_id); 
 
       
 
      //***************************************** 
 

 
      }, 
 
      error: function (jqXHR, textStatus, errorThrown) 
 
      { 
 
       alert('Failed'); 
 

 
      } 
 
     }); 
 
     // show bootstrap modal when complete loaded 
 
     $('#modal_open_appointment').modal('show'); 
 
     
 
     // Set title to Bootstrap modal title 
 
     $('.modal-title').text('Open Appointment'); 
 

 
    }, 
 
    error: function (jqXHR, textStatus, errorThrown) 
 
    { 
 
     alert('Error get data from ajax'); 
 
    } 
 
    }); 
 
} 
 

 

 
//button to call back the function with next id 
 
$('#next_patient').click(function() { 
 
    
 
    //recevice value & convert to number *** 
 
    var next_id = Number($(this).attr('data-next')); 
 
    
 
    open_appointment(next_id); 
 
}); 
 

 
//button to call back the function with previous id 
 
$('#previous_patient').click(function() { 
 
    
 
    //recevice value & convert to number *** 
 
    var prev_id = Number($(this).attr('data-prev')); 
 
    
 
    open_appointment(prev_id); 
 
});