简体   繁体   English

从MVC操作结果重定向的Javascript保留附加域

[英]Javascript redirect from MVC action result keeps appending domain

I am not an expert in javascript and have been struggling with the following for a while. 我不是javascript方面的专家,并且一直在努力解决以下问题。 I hope someone can guide me. 我希望有人可以指导我。

I have an action link on my MVC website like this 我在MVC网站上有这样的操作链接

<a href="@Url.Action("MyAction", "Home", new { name = "Test" })" class="myClick">
    <img alt="" src="@ViewBag.ImageUrl">
</a>

In my site.js file I have the following 在我的site.js文件中,我有以下内容

$(".myClick").on("click", function () {
    $.ajax({
        url: this.href,
        type: this.method,
        success: function (result) {
            window.open(result.Url, '_blank');
        }
    });
});

My controller action returns a JsonResult object allowing get and I do get the URL returned to my javascript function. 我的控制器操作返回一个JsonResult对象,该对象允许get并且我确实将URL返回到我的javascript函数。 The problem is the windoe.open keeps on opening with [myDomain]/[returnedUrl] 问题是windoe.open继续使用[myDomain] / [returnedUrl]打开

What am I doing wrong here? 我在这里做错了什么?

Make your url is an absolute url ( http://www.my.site.com ). 将您的网址设为绝对网址( http://www.my.site.com )。 Otherwise, your browser will interpret your url to be on the current domain automatically. 否则,您的浏览器会自动将您的网址解释为当前域中的网址。

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

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