shamju
shamju

Reputation: 1

codeigniter ajax

i have jquery script in

wamp/www/codeigni/js/script.php

and i have welcome.php as controller.and i wana access the method "getOneUserAjax" from controller 'welcome.php' through ajax from 'script.php'

 $.post("<?php echo site_url('/welcome/getOneUserAjax');?>",formData,function(data)
{
       alert("hi");
   alert("success");
});

and i tried severel other methods can how can igive path in script.php

Upvotes: 0

Views: 221

Answers (2)

Azam Alvi
Azam Alvi

Reputation: 7055

Suppose this is your base_url into autoload file

$config['base_url'] = 'http://localhost/site_name/';

Try this one into your script

$.post('<?php echo base_url()?>welcome/getOneUserAjax', 
          function(data) {

                  alert(data);
      });   

and suppose this is your class welcome.php and this is function getOneUserAjax

function getOneUserAjax()
{
     echo 'success';
}

Upvotes: 0

Mudshark
Mudshark

Reputation: 3253

If I understand correctly, your jQuery code inside /js/ needs to know the ajax controller/method url, correct? If so: in your view, before you call that jquery code, put the following:

<script>var base_url = '<?php echo base_url(); ?>';</script>

The base_url js-variable is now available to your jquery.

You should now be able to do something like:

$.post(base_url + "welcome/getOneUserAjax",formData,function(data){ //etc

Upvotes: 1

Related Questions