$.ajax(
{
type: 'GET',
url: 'ProductOp.aspx/getProduct',
data: '1',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
oldProduct = JSON.parse(msg.d);
}
});
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string getProduct(string ID)
{
ProductOperations productOp = new ProductOperations();
ProductObject product = productOp.Read(Convert.ToInt32(JsonConvert.DeserializeObject(ID)));
return JsonConvert.SerializeObject(product);
}
消息 「無效的Web服務調用,缺少值參數:‘ID’」 堆棧跟蹤
" konum: System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters) konum: System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters) konum: System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams) konum: System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)"
ExceptionType 「System.InvalidOperationException」
預先感謝您
非常感謝你這做了最後一個問題如果我想傳遞2個參數將「數據:{ID:1,名稱:ASD}」工作? –
是的,這將工作,但對於字符串使用單引號,你可以這樣做,數據:{ID:1,名稱:'asd'},請不要忘記標記爲答案:) –