Welcome Guest, Not a member yet? Register   Sign In
ajax functionality added
#1

Hi,

I am new fresher in codeigniter. i have developed a project where i want to submit form with ajax.so my question is which method is most preferable general ajax and jqery or codeigniter ajax helper and jquey helper.
Reply
#2

Here, you'll find a very good explanation:
https://scotch.io/tutorials/submitting-a...ith-jquery

Yes, you need jQuery.
In CI, the url in the Ajax call is crucial. In the example (see link) it's just "process.php", but that won't work. The url must have the controller + method which will handle the Ajax request. Like this:
PHP Code:
url '<?= base_url();?>controllername/methodname'

Hope this will help.
<?= is short for: <?php echo
Reply
#3

(This post was last modified: 11-10-2016, 02:42 PM by Gustavo Martins.)

(11-10-2016, 12:13 AM)Wouter60 Wrote:
PHP Code:
url '<?= base_url();?>controllername/methodname'

No doubt this code would work. But a better approach would be using the site_url() function.

I know both are similar but, the documentation encourages us to use site_url() 'any time you need to generate a local URL so that your pages become more portable in the event your URL changes.'

base_url() 'is useful because unlike site_url(), you can supply a string to a file, such as an image or stylesheet.'

So in my opinion, it's better to write this:

PHP Code:
url'<?= site_url('controllername/methodname'); ?>'

But again: Both ways are valid!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB