get "event" from ajax success
I was wondering if there's a way to get "event" from ajax success? For example:
UPDATE:
$.ajax({
type: "GET",
url: "/home/PersonInfo",
dataType: "json",
success: function(data) {
// I would like to use "data" like data.name, is this possible?
}
});
to
function MyEvents(start, end, callback) {
$.ajax({
type: "GET",
url: "/h开发者_C百科ome/GetInfo",
dataType: "json",
success: function(data) {
alert(data[0].start);
var events = [];
var meeting = new Date((data[0].start).getFullYear(),
(data[0].start).getMonth(),
(data[0].start).getDate());
while (meeting <= data[0].end) {
events.push({
id: data[0].id,
title: data[0].title,
start: new Date(meeting.valueOf()),
allDay: false
});
// increase by one week
meeting.setDate(meeting.getDate() + 7);
}
callback(events);
}
});
}
data[0].start).getFullYear() is not a function? this is the json returned: [{"start":1277985600,"end":1278158400}] Can anyone help?
The code you have should work, assuming /home/PersonInfo
gives you valid JSON like this:
{"name":"My Persons Name"}
Then data.name
will be "My Persons Name"
in your callback.
As a side note, Firebug / Chrome's Developer Tools should allow you to look at the actual request and see the returned JSON as an object. Plus they give you handy utilities for debugging like console.dir(data)
to print out the data.
Probably you have to use JQueri.getJSON() method, you can find documentation on jQuery Docs.
"/home/PersonInfo" needs to return a JSON object. What is your server side code written in?
精彩评论