500(内部服务器错误)发送post请求到aspx页面

本文关键字:请求 post aspx 页面 发送 内部 服务器 错误 | 更新日期: 2023-09-27 18:16:56

我想使用ajax将json文件从客户端发送到服务器端,json文件是"列表"。但我得到500(内部服务器错误)。如何解决这个问题?

这是jquery....

        $("#save").click(function () {
            $.ajax({
                type: "POST",
                url: "/external/ajax.aspx/OnSubmit",
                data: lists,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("Request: " + XMLHttpRequest.toString() + "'n'nStatus: " + textStatus + "'n'nError: " + errorThrown);
                },
                success: function (result) {
                    alert("We returned: " + result);
                }
            });
        });

这是包含web方法的aspx页面。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Services;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class iyesqueries_ajax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string OnSubmit(string json)
{
    return "hi";
}
}

请帮帮我....

500(内部服务器错误)发送post请求到aspx页面

你应该stringify列表

var response = { "list": lists };
data: JSON.stringify(response),
AND 
public static string OnSubmit(list<yourClazName> list)