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

前端 未结 5 548
闹比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:04

    Step 1, client side: You have to serialize your client objects into JSON, I personally use stringify() method of the JSON2 library: http://www.json.org/js.html

    data: JSON.stringify(myObj)
    

    Step2, Server-side: You have to translate the serialized object into something "eatable" by your c# code. Here you can use deserialize() method of Microsoft's JavaScriptSerializer class (but it might have some issues in .net 3.5 if you don't have SP installed), or otherwise JSON.net library http://james.newtonking.com/pages/json-net.aspx

    server-side method signature should be:

    fSaveToDB(Object myObj)
    

    where "myObj" is the name of your client-side object container:

    {myObj: your object...}
    

提交回复
热议问题