Result
@inherits Custom.Hybrid.Razor14
<button type="button" class="btn btn-primary" onclick="getPersons(this)">
Get Persons Custom
</button>
<button type="button" class="btn btn-primary" onclick="getPersonsAuto(this)">
Persons with Auto-Convert
</button>
<button type="button" class="btn btn-primary" onclick="getPersonsAutoPreserveCasing(this)">
Persons with Auto-Convert, preserve casing
</button>
<script>
function getPersons(moduleContext) {
$2sxc(moduleContext).webApi.fetchJson('books/persons')
.then(function(data) {
alert('Found ' + data.length + ' persons. \n'
+ 'The first one is "' + data[0].FirstName + ' ' + data[0].LastName + '"\n\n'
+ 'The raw JSON: \n' + JSON.stringify(data)
);
});
}
function getPersonsAuto(moduleContext) {
$2sxc(moduleContext).webApi.fetchJson('books/personsAuto')
.then(function(results) {
alert('On WebApi with Auto-Convert: Found ' + results.length + ' persons. \n'
+ 'The first one is "' + results[0].firstName + ' ' + results[0].lastName + '"\n\n'
+ 'The raw JSON: \n' + JSON.stringify(results)
);
});
}
function getPersonsAutoPreserveCasing(moduleContext) {
$2sxc(moduleContext).webApi.fetchJson('books/PersonsAutoPreserveCasing')
.then(function(results) {
alert('On WebApi with Auto-Convert: Found ' + results.length + ' persons. \n'
+ 'The first one is "' + results[0].FirstName + ' ' + results[0].LastName + '"\n\n'
+ 'The raw JSON: \n' + JSON.stringify(results)
);
});
}
</script>