简体   繁体   中英

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. I hope someone can guide me.

I have an action link on my MVC website like this

<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

$(".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. The problem is the windoe.open keeps on opening with [myDomain]/[returnedUrl]

What am I doing wrong here?

Make your url is an absolute url ( http://www.my.site.com ). Otherwise, your browser will interpret your url to be on the current domain automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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