在这里,我尝试用户选择主页,同时用户点击网站任何页面上的lnkfavourite按钮。当我将其他页面设置为主页时,它按预期工作,但不能使用default.aspx。此页面位于根目录。
VB页面背后:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lnkFavorite.Attributes("onclick") = "clearFave();"
end sub
JS / AJAX:
function clearFave() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
var params = "u=default.aspx";
req.open("POST", "/myaccount/favorite.aspx", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//req.setRequestHeader("Content-length", params.length);
//req.setRequestHeader("Connection", "close");
req.send(params); //Error here
var img = document.getElementById("ctl00_pageContent_imgFavorite");
if (img) {
img.src = img.src.replace("/favorite.png", "/unfavorite.png");
}
alert("This page is now set as your BERT home.");
}
}
最喜欢的页面:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Try
Dim u As String = "default.aspx"
If Request("u") IsNot Nothing Then
u = Request("u").Replace("|", "&")
End If
Profile.SetPropertyValue("favorite", u)
Profile.Save()
Catch ex As Exception
End Sub
答案 0 :(得分:0)
尝试更改帖子网址,使网址具体化。像这样http://doman:port/a-page
req.open('POST', 'http://yourdomain:port//myaccount/favorite.aspx')
答案 1 :(得分:0)
我从帖子网址中删除了'/'并且有效 来自:
req.open("POST", "/myaccount/favorite.aspx", true);
致:
req.open("POST", "myaccount/favorite.aspx", true);
:)