php - How to get jquery ajax response data and display in codeigniter view html div id -


i new in codeigniter.

i want display data in codeigniter view div id ajax on window load.

view.php

<script type='text/javascript' language='javascript'> $(window).load(function()  {     $.ajax({        type: "post",        url: "<?php echo base_url(); ?>colleges/index",               success: function(server_response        {            if(server_response == 'success')            {               $("#fillgrid").html(server_response);             }             else{               alert('not okay');            }                       }    });   //$.ajax ends here }); </script> 

i added explanations directly in code:

$(window).load(function()  {     $.ajax({        type: "post",        url: "<?php echo base_url(); ?>colleges/index",               success: function(server_response)           // added missing parenthesis        {            if(server_response == 'success')         // in success callback.            {                                                       $("#fillgrid").html(server_response);             }             else{               alert('not okay');            }                       }    });   //$.ajax ends here }); 

function simplifed:

$.ajax({     type: "post",     url: "<?php echo base_url(); ?>colleges/index",            success: function(server_response){         $("#fillgrid").html(server_response);      },     error: function(){         alert('not okay');     } });   //$.ajax ends here 

don't place ajax function inside .load() method !
.load jquery shorthand .ajax().
it's 1 or other... not both.

using .load(), be:

$("#fillgrid").load("<?php echo base_url(); ?>colleges/index"); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -