Welcome Guest, Not a member yet? Register   Sign In
Using ajax with codeigniter
#6

(01-14-2018, 02:07 PM)Wouter60 Wrote: jQuery will make life a lot easier. So, load jQuery in the head of your pages.
Have a look at the jQuery $.post() method.
Make sure the url that you pass to this method, starts with site_url().

Example.
If your controller is named Ajax_functions.php, and the method inside this controller is named test_ajax, then the url for the $.post() method (in your view) should be:
PHP Code:
var url "<?= site_url('ajax_functions/test_ajax');?>";
$.
posturl, { post-values } ) 
.
done(function(data){
 
  alert(data);
}); 

The test_ajax function should end with an echo statement.
The echoed text is the return value for the Ajax call in your view (the data part).
In this example, the return value is displayed in an alert box. But you can do all sorts of things with the return value in jQuery.

Good luck.

Thanks for this, the main issue I'm having is where I place the json files and how I categorise them?

The view should not be able to access the json should not be directly as they come under the model group. Is this correct?
Reply


Messages In This Thread
Using ajax with codeigniter - by Qodi - 01-14-2018, 09:50 AM
RE: Using ajax with codeigniter - by ignitedcms - 01-14-2018, 01:42 PM
RE: Using ajax with codeigniter - by jreklund - 01-14-2018, 01:46 PM
RE: Using ajax with codeigniter - by Wouter60 - 01-14-2018, 02:07 PM
RE: Using ajax with codeigniter - by Qodi - 01-19-2018, 09:26 PM
RE: Using ajax with codeigniter - by dave friend - 01-14-2018, 08:04 PM
RE: Using ajax with codeigniter - by dave friend - 01-20-2018, 09:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB