我正在尝试熟悉 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”响应:
登录到控制台时如下所示:
知道这里发生了什么吗?
最佳答案
您的网址错误。它是:
http://http://localhost:49852/Default.aspx
什么时候应该是:
http://localhost:49852/Default.aspx
关于c# - Ajax 请求后 .NET 后端的奇怪响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13976349/