0

我正在尝试将 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();
    }
}
4

1 回答 1

0

I was told that aspx is not intended to work this way, but that it can be done.

While probably not the ideal way to make an AJAX call to a .NET stack, this is not true.

I recommend debugging your server-side code to see why it is throwing the 500 error.

于 2012-10-22T17:53:52.257 回答