xajaccio
(Xajaccio)
April 24, 2012, 8:38am
1
LS,
For some reason the short URL in my Ajax call is not working:
$.ajax({
'url':'/customer/fetchSomething',
'success':function(result){
alert(result);
}
});
This is done in a JavScript file.
(The full URL is working fine, by the way. I am not allowed to post links just yet, so you’ll be missing the protocol part of the link, but you get the idea)
$.ajax({
'url':'localhost:8080/ogyii/index.php/customer/fetchSomething',
'success':function(result){
alert(result);
}
});
What am I doing wrong? Thanks!
sune
(Sune72net)
April 24, 2012, 10:13am
2
You will have to put index.php in as well:
‘url’:’/index.php/customer/fetchSomething’,
Best regards,
Sune
abennouna
(Abennouna)
April 24, 2012, 10:17am
3
For the following, you have to be in a PHP file to do it:
$.ajax({
'url':'<?php echo CController::createUrl('customer/fetchSomething'); ?>',
'success':function(result){
alert(result);
}
});
What I do personally, since I like separating JS from PHP, is to put the desired url or at least the static part of it in href of my ajax link, and then in my JS file :
$.ajax({
'url': $(this).attr('href'),
'success':function(result){
alert(result);
}
});
alex-w
(Pr0j3ct A1ex)
April 24, 2012, 10:18am
4
I think it’s because your site is in a subfolder.
try removing the first / from your short url.
xajaccio
(Xajaccio)
April 24, 2012, 10:43am
5
Indeed I do have to add my subfolder for it to work. And indeed the
CController::createUrl('customer/fetchSomething')
is the most elegant but unfortunaltely I am in a js file.
Thank you all very kindly!