Sending a JSON object to an ASP.NET web service using JQUERY ajax function

前端 未结 5 560
闹比i
闹比i 2021-02-09 22:29

I want to create object on the client side of aspx page. And i want to add functions to these javascript classes to make easier the life.

Actually i can get and use the

5条回答
  •  自闭症患者
    2021-02-09 23:31

    Let's simplify this: You have a server side object instance name and a client side object instance name.

    In your jQuery ajax - use this form

    data: '{"myServerSideObjectInstanceName":' + JSON.stringify(myClientSideObjectInstanceName) + '}',
    

    On the server side use

    public void MyWebServiceMethod(myObject myServerSideObjectInstanceName)
    { ... your code here ...}
    

    As long as the myObject has the identical signature as your javascript Object, this will work. You can get your values (on the server) using something like myServerSideObjectInstanceName.StudentName (or whatever).

提交回复
热议问题