简体   繁体   English

$ .post中具有多个网站的URL

[英]URL in $.post with multiples websites

I have a JavaScript to fill my address 我有一个JavaScript可以填写我的地址

  $.post('/Endereco/getEnderecos', { CardCode: dado }, function (data) {
    if (data) {
  (...)

My problem is: if i publish my website in 'localhost',works,but if i publish my website in "localhost/site" not work, is the same to "www.mydomain.com" and "www.mydomain.com/site" 我的问题是:如果我在“本地主机”中发布我的网站,但是,如果我在“本地主机/站点”中发布我的网站不起作用,则与“ www.mydomain.com”和“ www.mydomain.com/现场”

My website is Development in C# asp.net MVC3 IIS7 我的网站是使用C#开发的asp.net MVC3 IIS7

i have tried use the javascript to get the host, but not work 我曾尝试使用javascript来获取主机,但无法正常工作

Thanks 谢谢

You have a leading slash in your address /Endereco/getEnderecos , this will cause the browser to navigate to the root of the current host and then the URL you have provided. 您的地址/Endereco/getEnderecos有一个斜杠,这将导致浏览器导航到当前主机的根目录,然后导航到您提供的URL。

For example, posting to /somePage from a page at www.mysite.com/folder/subfolder/page will post to the url www.mysite.com/somePage . 例如,从位于www.mysite.com/folder/subfolder/page的页面发布到/somePage将会发布到URL www.mysite.com/somePage

To rectify this, remove the slash from before Endereco , so your post looks like this: 要解决此问题,请在Endereco之前删除斜线,因此您的post如下所示:

$.post('Endereco/getEnderecos', { CardCode: dado }, function (data) {
  if (data) {
(...)

In response to your comment, you could instead use the .. notation which means "go up a folder": 为了回应您的评论,您可以改用..表示法,表示“进入文件夹”:

$.post('../../Endereco/getEnderecos', { CardCode: dado }, function (data) {
  if (data) {
(...)

From localhost/order/Endereco/getEnderecos your resulting URL would be localhost/Endereco/getEnderecos , as we used two .. components, it has gone up two folders instead of one. localhost/order/Endereco/getEnderecos您得到的URL为localhost/Endereco/getEnderecos ,因为我们使用了两个..组件,所以它上升了两个文件夹而不是一个。

I was looking for some kind of tutorial on relative URLs and found this page: http://www.webreference.com/html/tutorial2/3.html . 我正在寻找某种有关相对URL的教程,并找到此页面: http : //www.webreference.com/html/tutorial2/3.html It might help you to better understand HTTP URLs =] 它可以帮助您更好地了解HTTP URL =]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM