jQuery ajax url problem

slimDeviant picture slimDeviant · Sep 22, 2010 · Viewed 8.5k times · Source

Ok a have an script for submiting input data. There is an url of my site going like this : http://www.<!mywebsite!>.com. This ajax request works perfectly when user is viewing my iste on http://www.<!mywebsite!>.com, but when he visits my site without www. e.g. http://<!mywebsite!>.com than the request doesn't works. I was wondering is there any way to handle this dynamically. Don't suggest redirection because that is not a good solution, cuz of google bots and website ranking. Thanks. Correct me if i said something wrong.

Answer

mkoistinen picture mkoistinen · Sep 22, 2010

This smells a bit like a same-origin policy issue.

In your ajax call, are you fully qualifying the destination URL?

i.e., do you have something like:

$.ajax({ url: 'http://www.whatever.com/script.php', ... });

If you do, change it to use a relative url like so:

$.ajax({ url: '/script.php', ... });

And let me (us) know if that helps.

Good luck!