我試圖重定向到新頁面點擊鏈接,但它重定向到新的頁面,它也在地址欄中添加前一頁的網址。請看看我的代碼。我如何刪除即將到來的頁面或下一頁上的當前頁面網址。點擊鏈接當前頁面的URL也被添加到即將推出的頁面上重定向
這是我的HTML。
@{
ViewData["Title"] = "ProductList";
}
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<h2>Product List</h2>
<div id="im" >
</div>
這是我的腳本。
<script>
$(document).ready(function() {
var loc = window.location.href;
var dat = loc.substring(loc.lastIndexOf('/') + 1);
$.ajax({
url:'api-url'
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "ProjectId": "1", "CategoryId": dat }),
success: function (data)
{
console.log(data);
$.each(data.ProductList, function() {
var list = "<a href='Product/ProductDetail/" + this.Id + "'><img src=" + this.ImageLink + " height=400 width=400> " + this.Name + "</a> $" + this.Price + " </img> ";
$("#im").append(list);
})
}
});
});
</script>
在重定向上,下一個頁面url變成這樣。
http://localhost:36547/Product/ProductList/Product/ProductDetail/102
相反,它應該是
http://localhost:36547/Product/ProductDetail/102
https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls – Luke
[絕對vs相對URL]的可能重複(https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls) – Luke