Sending a JSON object to an ASP.NET web service using JQUERY ajax function
- by uzay95
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 objects (derived from the server side classes) which returns from the services. When i wanted to send objects from the client by jquery ajax methods, i couldn't do it :)
This is my javascript object:
function ClassAndMark(_mark, _lesson){
this.Lesson = _lesson;
this.Mark = _mark;
}
function Student(_name, _surname, _classAndMark){
this.Name = _name;
this.SurName = _surname;
this.ClassAndMark = _classAndMark;
}
JSClass.prototype.fSaveToDB(){
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WS/SaveObject.asmx/fSaveToDB"),
data: ????????????,
dataType: "json"
});
}
Actually i don't know what should be definition of classes and methods on the Server side but i think:
class ClassAndMark{
public string Lesson ;
public string Mark ;
}
class Student{
public string Name ;
public string SurName ;
public ClassAndMark ClassAndMark ;
}
Web service is below but again i couldn't get what should be instead of the ???? :
[WebMethod()]
public void fSaveToDB(???? _obj)
{
// How can i convert input parameter/parameters
// of method in the server side object?
}