I am working on a jquery plugin which takes json data from the php page. Now i am trying to do the same thing in a asp.net web service. But i m finding hard to understand the php code. Also i cant host the php page in iis due to restrictions. Please help me to modify the code for asp.net webservice.
<?php
$year = date('Y');
$month = date('m');
echo json_encode(array(
array(
'id' => 111,
'title' => "Event1",
'start' => "$year-$month-10",
'url' => "http://yahoo.com/"
),
array(
'id' => 222,
'title' => "Event2",
'start' => "$year-$month-20",
'end' => "$year-$month-22",
'url' => "http://yahoo.com/"
)
));
?>
Jquery code for reading…
$(document).ready(function () {
$('#calendar').fullCalendar({
eventSources: [
// your event source
{
url: '/myfeed.php',
type: 'POST',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},
error: function () {
alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
]
});
});
Have a read of http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/ and http://encosia.com/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
The correct webservices should output JSON objects.
If you want a JSON serialiser then have a look at: http://json.codeplex.com/
Using @safarov’s code, you should be able to call the serialise method to return it as a JSON string: