Reputation: 57
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....
Upvotes: 0
Views: 1163
Reputation: 2437
you should stringify the list
var response = { "list": lists };
data: JSON.stringify(response),
AND
public static string OnSubmit(list<yourClazName> list)
Upvotes: 1