views:

115

answers:

3

I have following method in wcf webenabled service

Public Person AddPerson(Person p);

As of now in traditional asp.net application i am using scriptmanager and it allows me to created javascript object like following to pass it in ajax call

var person = Person();
person.name = "mamu";
phonenumber = 911;
ajaxService.AddPerson(person, callback(),null, null);

Now i want to try same thing in asp.net mvc using jquery. But var person = Person(); can't be used any more as there is no script manager. scriptmanager has been taking care or conversion stuff so far but looks like jquery doesn't do it or at least not same way.

How can i build this Person object on client-side javascript to use this jquery .ajax call?

A: 

I suspect that the person constructor is just creating a regular javascript object. You could easily replicate this.

var person = {};
person.name = "mamu";
person.phonenumber = 911;
ajaxService.AddPerson( person, callback(), null, null );
tvanfosson
A: 

see my accepted answer here

redsquare
+2  A: 
// create the Person object, case sensitive
var personObj = {name: "mamu", phonenumber: "911"};

// the callback function when post is successful
var onAddPersonSuccess = function(returnData) { 
  // do something with the returnData if needed 
};

// the post to your webservice or page
$.ajax({
 type: "POST",
 url: "YourPage.aspx/AddPerson",
 data: json,
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: onAddPersonSuccess
});