Ajax - .cshtml调用错误
本文关键字:错误 调用 cshtml Ajax | 更新日期: 2023-09-27 18:03:05
我有下一个问题:我正在创建一个ajax调用。cshtml文件…在本地主机,它工作得很好,但当上传到服务器上时,它抛出一个错误"禁止(403)"。
这是我的ajax调用:$.ajax({
type: "GET",
url: "~/MyProcessPage.cshtml",
contentType: "application/x-www-form-urlencoded",
data: { id: 1 },
crossDomain: true,
success: function (res) {
console.log(res);
},
error: function (res) { console.log(res); },
dataType: 'json'
});
这是我的c#代码:
if (HttpContext.Current.Request.HttpMethod == "GET")
{
var id= Convert.ToInt32(Request.QueryString["id"]);
Response.Write(id);
}
请注意,我使用剃刀,但不使用MVC!
谢谢!
也许你应该改变url
$.ajax({
type: "GET",
url: '@Url.Content("~/MyProcessPage.cshtml")',
contentType: "application/x-www-form-urlencoded",
data: { id: 1 },
crossDomain: true,
success: function (res) {
console.log(res);
},
error: function (res) { console.log(res); },
dataType: 'json'
});