Kaan Özcan
Kaan Özcan

Reputation: 82

Web method ajax get giving 500 Internal Server Error

        $.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);
    }

gives me

Message "Invalid web service call, missing value for parameter: 'ID'." StackTrace

" 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"

Thank You in Advance

Upvotes: 0

Views: 11146

Answers (3)

solanki dev
solanki dev

Reputation: 27

 var obj = "yhdgfhgfh";

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

      dataType: "json",

 });

Upvotes: 0

Altaf Sami
Altaf Sami

Reputation: 846

add Id param in data:

$.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);
        }
    });

Upvotes: 3

Sora
Sora

Reputation: 2551

   $.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);
        }
    });

Upvotes: 2

Related Questions