jquery - PHP: Unable to get the json output into my javascript page as a variable value -


this question has answer here:

i have output in format var sampletags = ['c++', 'scala'];

my javascript function is:

 <script>             $(document).ready(function(){         $(function(){                var sampletags;              $.ajax({                 url:"<?php echo base_url('ajax_get_tags/gettags'); ?>"             }).done(function(data) {                 if (data) {                    sampletags = data;                 }             });        ......................         .......................     $(function(){        var sampletags = <?php echo json_encode($query) ?>; 

my php controller

   function gettags(){     $json_array=$this->tagsmodel->get_all_tags();     echo json_encode($json_array);   } 

my model

 //-------------------------------function tags-------------------------------- function get_all_tags() {      $this->load->database();     $this->db->limit('10');     $this->db->select('tags_name');     $res = $this->db->get('tags');     $ret = array();      foreach ($res->result_array() $row) {           $ret[] = $row['tags_name'];     }      return $ret; } 

how can json output ajax request display value javascript variable? please me solve issue..

you're using older version of jquery, .done won't work. looks want add key request object called complete, anonymous function value:

$.ajax({   url: "<?php echo base_url('ajax_get_tags/gettags'); ?>",   complete: function(data) {       if (data) {           sampletags = data;       }   } }); 

i found out googling error message. 1 of results question: object #<xmlhttprequest> has no method 'done'. have googled error message , figured out yourself.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -