1

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?

2 Answers 2

2
// 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
});
Sign up to request clarification or add additional context in comments.

Comments

0

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 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.