簡體   English   中英

500(內部服務器錯誤),用於將發布請求發送到aspx頁面

[英]500 (Internal Server Error) for sending post request to aspx page

我想使用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";
}
}

請在這件事上給予我幫助....

你應該字符串化的列表

var response = { "list": lists };

data: JSON.stringify(response),

AND 

public static string OnSubmit(list<yourClazName> list)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM