我有一个简单的web方法和ajax调用,并继续收到一个错误,指出它无法将字符串转换为IDictionary对象?将参数传递给WebMethod with jQuery Ajax
这里是Ajax调用:
var params = '{"ID":"' + rowid + '"}';
$.ajax({
url: 'EDI.asmx/GetPartnerDetails',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(params),
dataType: "json", //not json . let me try to parse
success: function(msg, st) { . . . .
这里是WEBMETHOD:
<WebMethod()> _
Public Function GetPartnerDetails(ByVal ID As String) As String
'Dim objParam As IDictionary = CType(JsonConvert.DeserializeObject(ID), IDictionary)
'Dim rowID As String = objParam("ID")
Dim objController As New HealthComp.BLL.X12Partners.TradingPartnersController
Dim objInfo As TradingPartnersInfo = objController.FetchByPartnerID(Int32.Parse(ID))
Return JsonConvert.SerializeObject(objInfo)
End Function
下面是我从萤火看到:
响应头
服务器:Microsoft-IIS /5.1
日期:2009年4月9日星期四21:43:59 GMT
jsonerror:true
Cache-Control:private
Content-Type:application/json;字符集= UTF-8
内容长度:1331
POST: “{\” ID \ “:\” 4 \ “}”
RESPONSE:
{ “消息”:“不能将\ u0027System.String \ u0027类型的对象转换为\ u0027System.Collections .Generic.IDictionary`2 [System.String,System.Object] \ u0027“,”StackTrace“:”at System.Web.Script.Serialization .ObjectConverter.ConvertObjectToTypeInternal(Object o,Type type,JavaScriptSerializer序列化程序,布尔型 throwOnError,Object & convertedObject)\ r \ n System.Web.Scri pt.Serialization.ObjectConverter.ConvertObjectToTypeMain (Object o,Type type,JavaScriptSerializer serializer,Boolean throwOnError,Object & convertedObject )\ r \ n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o,Type type,JavaScriptSerializer serializer)\ r \ n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer,String input,Type type,Int32 depthLimit)\ r \ n at System.Web.Script.Serialization.JavaScriptSerializer .Deserialize [T](String input)\ r \ n在System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest (HttpContext上下文,JavaScriptSerializer序列化程序)\ r \ n在System.Web.Script.Services.RestHandler .GetRawParams(WebServiceMethodData methodD ATA,HttpContext的背景下)\ r \ n在System.Web.Script.Services .RestHandler.ExecuteWebServiceCall(HttpContext的背景下,WebServiceMethodData methodData)”, “ExceptionType” : “System.InvalidOperationException”}
任何人有任何想法对这个?谢谢!!
你是男人。非常感谢Chris!我添加了这个:var jsonText = JSON.stringify({ID:rowid});阅读完文章后。我读过大量的文章,显示传递参数与报价。你是我读过的第一个解释并固定它的人。 Mucho gracias! – 2009-04-09 22:17:50
很高兴有帮助。 – 2009-04-09 22:19:07