javascript - JS/AJAX 加载资源失败,服务器响应状态为 404(未找到)
问题描述
在这里,当用户单击网站任何页面上的 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
解决方案
尝试更改帖子 URL,使 URL 特定。像这样http://doman:port/a-page
req.open('POST', 'http://yourdomain:port//myaccount/favorite.aspx')
推荐阅读
- hive - Hive 备份和恢复
- css - 如何在 CSS 中创建链接
- maven-3 - 我正在尝试使用 Arquillian 智能测试库但没有成功
- python - 我的 Postgresql COPY 事务还在运行吗?
- python - 为什么第二个 request.session cookie 返回空?
- node.js - 当我尝试创建反应项目时出现错误
- excel - Application.inputbox 在范围选择上抛出错误 424
- database - 如何遍历数据库中已经存在的对象并更新字段?
- ffmpeg - discord.errors.ClientException:找不到 C:/ffmpeg/bin/ffmpeg
- python - 无法将 override_settings 类装饰器与 setUpClass 和 tearDownClass Django 一起使用