我正在尝试将 AJAX 请求从标准 .html 页面发送到 .aspx 页面。我只是想看看这是否可以完成,但我不断收到“状态代码:HTTP/1.1 500 内部服务器错误”。有人告诉我,aspx 不打算以这种方式工作,但可以做到。
我的Javascript:
function handleload(e) {
alert(req.responseText);
}
var req = new XMLHttpRequest();
req.open('POST', 'helloworld.aspx' , true);
req.addEventListener('error', function(e) {console.log(e)}, false);
req.addEventListener('load', handleload, false);
req.send();
我的 aspx 页面:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="helloworld.aspx.cs" Inherits="helloworld" %>
我的 aspx.cs 页面:
using System;
public partial class helloworld : System.Web.UI.Page
{
public void Page_Load()
{
Response.ContentType = 'text/html';
Response.Write("Hello World!")
Response.End();
}
}