CodeIgniter Forums
Ajax funcation call - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Ajax funcation call (/thread-70805.html)

Ajax funcation call - codeigniternishant - 06-02-2018

Hi, Need help to resolve ajax call issue
In my view page ( working on codeigniter), there is a dropdown and a div section. Based on dropdown value, data will get change in div section. I am using ajax call ( to call method in controller) to upload data in div tag on dropdown change event. Ajax call working fine on first change event of dropdown but when i select any other value in dropdown, ajax function call is not working ( second select and so on). 
My code is:
$(document).ready(function() {
   $("body").on('change','#assettype_id',function(e){    // "assettype_id" is dropdown id
       var categoryval = $('#assettype_id :selected').val();
                  type: 'POST',
                  cache: false,
                  url: 'http://my_path/index.php/assetcontroller/assignpc/'+ categoryval,  // Based on "categoryval" data will change in div tag 
                  dataType: 'html',
                  success: function(data) {
                  $( "#result" ).load( "http://my_path/index.php/assetcontroller/assignpc/"+ categoryval);  // "result" is div tag id
                  $( "#result" ).html(categoryval);   
        return false;

Why ajax call is not working in dropdown second ( so on) change event? 
Thanks in advance

RE: Ajax funcation call - codeigniternishant - 06-04-2018

My purpose is: i have a view page with two section: section one contains a dropdown and second section is used to load data that comes from a another view based on dropdown's selected value? How to make code for this in codeigniter?