c# - Ajax 请求后 .NET 后端的奇怪响应

标签 c# asp.net .net ajax extjs

我正在尝试熟悉 ASP .net,因此在“hello world”之后,我尝试添加一些简单的后端请求处理。所以我正在从我的页面向 asp 页面发出 Ajax 请求:

    Ext.Ajax.request({
        type: 'POST',
        url: 'http://http://localhost:49852/Default.aspx',
        params: {
            html        : {'array': document.body.innerHTML}
        },
        success : function(response){
        console.log('RESPONSE !', response);
            //me.onSuccess(response, callback, errback);
        },
        failure : function(response){
            console.log('RESPONSE FAIL !', response);
        }
    });

这是我的页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

及其背后的代码(我不确定结构是否应该像这样,但我找不到任何不使用表单的请求处理示例):

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page{
    protected void Page_Load(object sender, EventArgs e){
        if (this.Request["html"] != null){
            this.Response.Write("{'success': true, 'msg': 'Its working'}");
       }
        else{
            this.Response.Write("{'success': false, 'msg': 'Error in request data.'}");
        }
    }
}

现在,如果我在浏览器中访问该地址,就会显示正确的(错误的)文本。但是当我尝试使用 XHR 请求时,我在 Firebug 控制台中根本看不到任何请求,并且在 Net 选项卡中我收到“OPTIONS”响应:

enter image description here

登录到控制台时如下所示:

enter image description here

知道这里发生了什么吗?

最佳答案

您的网址错误。它是:

http://http://localhost:49852/Default.aspx

什么时候应该是:

http://localhost:49852/Default.aspx

关于c# - Ajax 请求后 .NET 后端的奇怪响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13976349/

相关文章:

c# - 如何检测用户何时单击 WebView 控件中的超链接?

javascript - 无法使用 Asp.Net 查看 Google map ,错误为 :InvalidKeyOrUnauthorizedURLmapError

asp.net - 将 Monolith ASP.NET Webform 应用程序移动到微服务和 session 管理

.net - 使用 concat() 从 mysql 存储过程检索并绑定(bind)到 datagridview 时出错

c# - 直接在屏幕上绘图时如何清理自己

.net - 由于以下错误 : 80080005,检索具有 CLSID {XXXX} 的组件的 COM 类工厂失败

c# - 从 webapp 下载 zip 文件

java - 在 C# 中验证在 Java 中签名的内容

c# - 没有返回类型协变的接口(interface)继承

c# - 如何在没有回发或更新面板的情况下获取 DropdownList 的 SelectedValue