我正在尝试熟悉 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 控制台中根本看不到任何请求,并且在“网络”选项卡中我得到“选项”响应:
登录到控制台时如下所示:
有什么想法吗?