简体   繁体   中英

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

I want to send the json file from client side to server side using ajax, the json file is the "lists". But I'm getting 500(Internal server error). How to solve this problem...

This is the 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);
                }
            });
        });

This is the aspx page containing the web method.

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";
}
}

Please help me with this....

you should stringify the list

var response = { "list": lists };

data: JSON.stringify(response),

AND 

public static string OnSubmit(list<yourClazName> list)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM