This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. Learn More

Using Jquery And Ajax With Codeigniter

Using Jquery And Ajax With Codeigniter Web-development (jquery) Using Jquery And Ajax With Codeigniter

Using jQuery and ajax with Codeigniter
Using jQuery and ajax with Codeigniter

change the ajax url parameter to this:
url: <?php echo base_url().'profiles/get_all_users';?>
http://www.yourdomain.com/products/get_all_users



<?php //products controller class Products extends CI_Controller{ function __construct(){ parent::__construct(); } public function get_all_users(){ $query = $this->db->get('products'); if($query->num_rows > 0){ $header = false; $output_string = ''; $output_string .= "<table>\n"; foreach ($query->result() as $row){ $output_string .= '<tr>\n'; $output_string .= "<th>{$row['value']}</th>\n"; $output_string .= '</tr>\n'; } $output_string .= '</table>\n'; } else{ $output_string = 'There are no results'; } echo json_encode($output_string); } } ?> 
<html> <script language='JavaScript' type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <title>Display Page</title> </head> <body> <button type='button' name='getdata'>Get Data.</button> <div> </div> <script type='text/javascript' language='javascript'> $('#getdata').click(function(){ $.ajax({ url: '<?php echo base_url().'profiles/get_all_users';?>', type:'POST', dataType: 'json', success: function(output_string){ $('#result_table').append(output_string); } // End of success function of ajax form }); // End of ajax call }); </script> </body> </html> 

0 Response to "Using Jquery And Ajax With Codeigniter"

Posting Komentar

Contact

Nama

Email *

Pesan *