I'm using the $ajax interface, working from localhost.
First example works as expected, RequestUrl (seen e.g. in Chrome Developer tools network tab) is: /commentSubmitted
$.ajax({
type: "POST",
url: '/commentSubmitted',
data: "hi"});
This here doesn't work as expected, it appends the current browser url (referrer) to it:
$.ajax({
type: "POST",
url: 'anyotherstring/commentSubmitted',
data: "hi"});
I would lik开发者_开发知识库e to have the RequestUrl always be the exact string I specify. For some reason the RequestUrl looks like this: /nested/url/I/dont/care/about/anyotherstring/commentSubmitted
The second example, due to the nature of relative URLs, appends "anyotherstring/commentSubmitted" to wherever you are now. So if you're at "/nested/url/I/dont/care/about/", that's where the POST request would go.
Instead, begin with a "/" to specify an absolute path.
Try adding a slash.
url: '/anyotherstring/commentSubmitted',
The first example begins width slash, which means "strip old address and put this one right behind the domain name". In the second example, you are using a relative address, which is always appended at the end of current URL. It is similar to if you put it into href or src attribute.
精彩评论