user1504222
user1504222

Reputation: 267

Execute ajax on button click

I use this jquery into a modal with a select. When user select an option, document_fetch.php is called and some extra field are showed to user.

I'm like to use same modal to EDIT data.

If I add

$("#class_id").val("2").change();

and I open a modal select value appear correctly.

There is a way to start ajax request by clicking the button for open modal, for example?

$(document).ready(function(){ 



    $('#class_id').change(function(){  
    
       var cnt_man_class_doc_id = $(this).val();
       var cnt_man_folder_id = <?php echo $cnt_man_folder_id; ?>;
       
       $.ajax({
            url:"document_fetch.php",  
            method:"POST",  
            data:{cnt_man_class_doc_id:cnt_man_class_doc_id,
                  cnt_man_folder_id:cnt_man_folder_id
                 }, 
            success:function(data){  
                 $('#show_product').html(data);  
                 
            }
       });
    });



 });

Upvotes: 1

Views: 43

Answers (1)

Hid Dencum
Hid Dencum

Reputation: 592

$("#class_id").val("1").change();
  
$("#YourButtonId").on("click", function(e) {
e.preventDefault();

var cnt_man_class_doc_id = $(this).val();
var cnt_man_folder_id = <?php echo $cnt_man_folder_id; ?>;
       
       $.ajax({
            url:"document_fetch.php",  
            method:"POST",  
            data:{cnt_man_class_doc_id:cnt_man_class_doc_id,
                  cnt_man_folder_id:cnt_man_folder_id
                 }, 
            success:function(data){  
                 $('#show_product').html(data);  
                 
            }
       });
       
});

Upvotes: 1

Related Questions