简体   繁体   中英

Jtable An error occured while communicating to the server. - post 500 error

when i am adding a new record i have the above error below is my code, i am stuck done some search on google but i am going nowhere i would be greateful if someone can point me in the right direction.

 $('#dataContent').jtable({
            title: 'Data List',
            paging: true,
            pageSize: 5,
            actions: {
                listAction:'/Test.aspx/GetAllCars',
                createAction: 'Test.aspx/CreateCar'

            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                Make: {
                    title: 'Make',
                    width: '20%'
                },
                Model: {
                    title: 'Model',
                    width: '20%'
                },
                Engine: {
                    title: 'Engine',
                    width: '20%'
                },
                Year: {
                    title: 'Year',
                    width: '20%'
                }
            }

        });

        $('#dataContent').jtable('load');

    });


    [WebMethod(EnableSession = true)]
    public static Object CreateCar(Car c) {
        try {
            bool addresult = new CarRepo().CreateCar(c);
            return new { Result = "OK" };

        }
        catch (Exception ex) {
            return new { Result = "ERROR", Message = ex.Message };
        }

    }


 public bool CreateCar(Car c) {

        using(var context = new DAL.DbAccess.DataContext()) {
            try {
              var Irepo = new DAL.Repository.MainRepository<Car>(context);
              Irepo.Insert(c);
              return true;
            } catch(Exception ex) {
                ex.ToString();
                return false;
            }

        }
    }

POST http://localhost:51598/Test.aspx/GetAllCars

200 OK 4ms jquery-....min.js (line 3) POST http://localhost:51598/Test.aspx/CreateCar

500 Internal Server Error 7ms jquery-....min.js (line 3) HeadersPostResponseJSON

{"Message":"Invalid web service call, missing value for parameter: \'c\'.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary 2 parameters)\\r\\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary 2 parameters)\\r\\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\\r\\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

500 is a server unexpected condition code. This doesn't look like a JavaScript issue. You are using a .Net aspx page. You may want to be sure the IIS server is setup and functioning correctly.

http://www.w3.org/Protocols/HTTP/HTRESP.html

find the problem it should be

     [WebMethod(EnableSession = true)]
     public static Object CreateCar(Car **record**) {
         try {
            bool addresult = new CarRepo().CreateCar(record);
            return new { Result = "OK" };

        }
        catch (Exception ex) {
            return new { Result = "ERROR", Message = ex.Message };
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM