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 dat开发者_如何学运维a 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?
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);
};
精彩评论