Welcome Guest, Not a member yet? Register   Sign In
how to get url from ajax
#1

[eluser]php beginner[/eluser]
I want ajax url from view file in controller for pagination.
#2

[eluser]theprodigy[/eluser]
you could pass the url in as a parameter, or try using $_SERVER['HTTP_REFERER']; and see if that works (I'm not sure if the second will work. I've never tried with ajax)
#3

[eluser]pickupman[/eluser]
Just use site_url() function. In jQuery, I've used:
Code:
$.ajax({
  url: "<?php echo site_url('controller/function');?>",
  //the rest of the options...

});
#4

[eluser]theprodigy[/eluser]
I thought it was the other way around. I thought they wanted to know in the controller, what page it was that called it, not knowing in the view what page to call. Although, I could be wrong
#5

[eluser]pickupman[/eluser]
Ahh...I read it the wrong way. Passing a param is a good idea, but how are you using the code in the controller? Shouldn't you already know where it is coming from?
#6

[eluser]theprodigy[/eluser]
not necessarily. If you are using a sub-view type setup (main site template + sub-views to fill content), and have an auto generated table with pagination, you would need to pass the url back to the controller for the pagination class to build the links.
#7

[eluser]php beginner[/eluser]
yes i am passing url as parameter but i never wants to change base url
#8

[eluser]Zeeshan Rasool[/eluser]
If your just want to get base url or any specific url and want to use it in js files where you are doing ajax calls then, declare a JS variable at header section of your main.php or index file and assign your value to it.
<html>
<head>
var my_url = '<?=base_url?>/site/';
</head>
...
...




Theme © iAndrew 2016 - Forum software by © MyBB