views:

60

answers:

2

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.

+2  A: 

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!

mkoistinen
A: 

You should use relative path in your query. The problem with using absolute path with the server address is that with Ajax you can't do request to an other domain than the one you are on currently on.

You need to know that http://www.example.com/ is not on the same domain as http://example.com/

See this for more detail on the same origin policy that applies to Ajax request.

http://en.wikipedia.org/wiki/Same_origin_policy

HoLyVieR