Problem with Ajax short url

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!

You will have to put index.php in as well:

‘url’:’/index.php/customer/fetchSomething’,

Best regards,

Sune

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);

     }

});

I think it’s because your site is in a subfolder.

try removing the first / from your short url.

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!