【发布时间】:2017-11-01 00:11:30
【问题描述】:
我试图在单击链接时重定向到新页面,但它会重定向到新页面,它还会在地址栏中添加上一页 URL。请看看我的代码。如何删除即将到来的页面或下一页上的当前页面 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
【问题讨论】:
标签: javascript jquery asp.net-mvc api