我正在使用ASP.NET MVC.When开发一个网页--我使用aJax请求一个子页面内容,url附加一个"#“automatic.Before automatic.Before aJax,url想要这样:http://a.travel.com/product/index,在aJax请求之后,url会这样想:http://a.travel.com/product/index#.This是my aJax请求代码:
function GetProductByTag(tagId, source) {
var keyword = $("#serachInput").val();
if (keyword == null) {
return;
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
document.getElementById("productList").innerHTML = xhr.responseText;
} else {
xhr.abort();
alert("Too many request!");
}
}
}
xhr.open("Post", "/Product/ProductList?tagId=" + tagId + "&pageIndex=1", true);
}
xhr.send(null);
}响应文本是产品列表信息(Html)。
这是我的页面列表代码的一部分:
<li onclick="ClickProductList(1,'http://www.ly.com/scenery/BookSceneryTicket_2287.html?spm=1.68076534.156.4&refid=75866398')" class="top">
<a href="#">
<img src="/WCF_UploadFile/TourProductPhoto/20160125143157LWTIW.jpg">
<h6>
<span>35</span>
</h6>
<p></p>
</a>
</li>为什么会发生这种情况,如何避免?
发布于 2016-01-25 08:17:14
如果触发事件的锚元素具有href="#“,那么它将导致浏览器这样做。
如果您完全删除href元素,它应该可以工作,并且不会触发url更改。
但是,您可能需要更改您的CSS,因为没有href的锚点失去了一些样式,例如游标。
a:hover {
cursor:pointer;
}https://stackoverflow.com/questions/34987783
复制相似问题