frenchie
frenchie

Reputation: 51937

accessing the json return variable

I have an ajax call handled with jquery like this:

var GetAppointmentDate = "{'DateInput' : '02/02/2011'}";

$(function () {

    $("#mydiv").click(function () {

        $.ajax({
            type: "POST",
            url: "../Pages/Appointments.aspx/GetAppointements",
            data: GetAppointmentDate,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: successFn,
            error: errorFn
        });
    });
});

I've been debuggging the code behind to the point where I know the returned data is what I want: the page method end with "return result;" and the variable result contains the json strong I need. Now how do I access the data returned in the front-end.

So far I have:

function successFn(){
    alert(msg.d);
};

Nothing's being outputted. What am I missing?

Upvotes: 0

Views: 195

Answers (1)

Chandu
Chandu

Reputation: 82903

Change your success function to accept a parameter and then you can refer to the returned data. i.e:

function successFn(msg){
    alert(msg.d);
};

Upvotes: 2

Related Questions