weixin_33716557 2016-08-19 16:06 采纳率: 0%
浏览 109

Ajax-.cshtml调用错误

i have the next problem: i'm creating an ajax call to a .cshtml file... in localhost it works fine, but when uploaded on server it throws an error "Forbidden (403)"

this is my ajax call:

$.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'
});

and this is my C# code:

if (HttpContext.Current.Request.HttpMethod == "GET")
{
    var id= Convert.ToInt32(Request.QueryString["id"]);
    Response.Write(id);
}      

Please notice i'm using razor but NOT using MVC!

Thanks!

  • 写回答

1条回答 默认 最新

  • weixin_33694172 2016-08-19 16:09
    关注

    Maybe you shold change the 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'
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services