我需要一个带有 c# webforms 代码的 jquery 序列化数据,我尝试这种方式:
jQuery.ajax({
type: "POST",
url: "book_de_acoes.aspx/salvarSimulacaoAutomatica",
data: JSON.stringify({ form: jQuery("#aspnetForm").serialize() }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (callback) {
alert(callback);
}
});
后面的c#代码:
[WebMethod(true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static bool salvarSimulacaoAutomatica(string form)
{
try
{
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
var formData = js.Deserialize<object>(form);
}
catch(Exception e)
{
}
return true;
}
但客场得到一个错误:
System.ArgumentException:无效的 JSON 原语:ctl00。在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 深度) 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(字符串输入,Int32 depthLimit,JavaScriptSerializer序列化程序)在 System.Web.Script.Serializer.JavaScriptSerializer.Deserialize(JavaScriptSerializer 序列化程序,字符串输入,类型类型,Int32 depthLimit)在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](字符串输入)在 PortalSuvinil.admin_portal .book.book_de_acoes.salvarSimulacaoAutomatica(字符串形式)
获取这些数据的正确方法是什么?