<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
Now copy and paste below code in your
page. You have to change URL and Artist object according to your need.
<script type="text/javascript">
$("#btnEvent").live("click", function () {
debugger;
var myDate = '2016.06.26' //set from date here
var jsondate = convertToJSONDate(myDate)
var artist = {}; // object for request
artist.SearchArtist = "t"; //Artist to be search
artist.State = "NSW";
artist.Suburb = "Sydney";
artist.Postcode = 2000;
artist.DateForm = convertToJSONDate(myDate) // convert from date to json
artist.TotalEventsToReturn = 80;
var jsonstng = "{\"artist\":" + JSON.stringify(artist) + "}"; // add root name if you need
//Post request to Live Guide Service
$.ajax({
type: "POST",
contentType: "application/json;
charset=utf-8",
url:
'http://local.abc.com.au/AbcDataAPI.svc/GetArtistEvents',//you can set local host
headers: { 'AccessToken': '5347-c48b-4803-9056-6869' },//your API key
data: jsonstng,
dataType: "json",
processData: false,
success: function(result) {
for (var i = 0; i <
result.GetArtistEventsResult.Events.length; i++) {
$("#Events").append("<tr><td>" +
result.GetArtistEventsResult.Events[i].Name + "</td><td>" + result.GetArtistEventsResult.Events[i].Artists
+ "</td>");
}
},
error: function (result) {
alert(result);
}
});
});
// Function to convert javascript date to
json date
function convertToJSONDate(myDate) {
var dt = new Date(myDate);
var newDate = new Date(Date.UTC(dt.getFullYear(),
dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(),
dt.getMilliseconds()));
return '/Date(' + newDate.getTime() + ')/';
}
</script>
// Code Sample for body
section
<form id="form1" runat="server">
<div>
<div>
<input type="button" id = "btnEvent" value="Get Events" />
<table id="Events" border='1'>
<tr>
<th>Name</th>
<th>Artists</th>
</tr>
</table>
</div>
</div>
</form>
No comments:
Post a Comment