0
        $.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)"

异常类型“System.InvalidOperationException”

先感谢您

4

3 回答 3

3

在数据中添加 ID 参数:

$.ajax(
    {
        type: 'GET',
        url: 'ProductOp.aspx/getProduct',
        data: { ID: 1 },
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (msg) {
            oldProduct = JSON.parse(msg.d);
        }
    });
于 2013-06-13T10:49:17.257 回答
2
   $.ajax(
    {
        type: 'GET',
        url: 'ProductOp.aspx/getProduct',
        data: '{ID:'1'}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (msg) {
            oldProduct = JSON.parse(msg.d);
        }
    });
于 2013-06-13T10:49:10.453 回答
0
 var obj = "yhdgfhgfh";

 $.ajax({
      type: "GET",
      url: Url,
      data: { data: "hggfh" },
      contentType: "application/json; charset=utf-8",
      // data: "{'data' : '" + obj + "'}",

      dataType: "json",

 });
于 2015-04-20T07:24:04.103 回答