Welcome Guest, Not a member yet? Register   Sign In
How to point to a controlle from a js file?
#1

[eluser]chefnelone[/eluser]
Hello.

I'm doing a ajax call (using jquery) from a js file like this:

Code:
$.post("http://www.mysite.com/site/order", order, function(theResponse)...

where site is the controller and order is the method
Is there any way to point the controller with this line:

Code:
$.post("site/order", order, function(theResponse)...

or should I use <?php echo base_url(); ?> in the js file as well?
#2

[eluser]Dyllon[/eluser]
I like to define my base URI, module/controller, and method in my view header so I can use them in any javascripts.

Code:
var BASE_URI        = "<?php echo base_url(); ?>";
var CI_CONTROLLER   = "<?php echo $controller; ?>";
var CI_METHOD       = "<?php echo $method; ?>";

Then use the variables in your javascript

Code:
$.post(BASE_URI + CI_CONTROLLER + '/' + CI_METHOD, order, function(theResponse)...
#3

[eluser]chefnelone[/eluser]
[quote author="Dyllon" date="1264549311"]I like to define my base URI, module/controller, and method in my view header so I can use them in any javascripts.

Code:
var BASE_URI        = "<?php echo base_url(); ?>";
var CI_CONTROLLER   = "<?php echo $controller; ?>";
var CI_METHOD       = "<?php echo $method; ?>";

Then use the variables in your javascript

Code:
$.post(BASE_URI + CI_CONTROLLER + '/' + CI_METHOD, order, function(theResponse)...
[/quote]

I had already found a solution, but I'll try your idea as well
thanks.
#4

[eluser]Haqqi[/eluser]
[quote author="chefnelone" date="1264614088"][quote author="Dyllon" date="1264549311"]I like to define my base URI, module/controller, and method in my view header so I can use them in any javascripts.

Code:
var BASE_URI        = "<?php echo base_url(); ?>";
var CI_CONTROLLER   = "<?php echo $controller; ?>";
var CI_METHOD       = "<?php echo $method; ?>";

Then use the variables in your javascript

Code:
$.post(BASE_URI + CI_CONTROLLER + '/' + CI_METHOD, order, function(theResponse)...
[/quote]

I had already found a solution, but I'll try your idea as well
thanks.[/quote]

Can you provide your solution too??




Theme © iAndrew 2016 - Forum software by © MyBB