3. JavaScript Codebeispiel
Das JavaScript Codebeispiel zeigt die Ausgabe eines Berichts über ein vordefiniertes Export-Profil und die Anzeige im Browser.
var host = 'http://myreportserver/rs';
// Define authentication parameters
// When requesting the exported files, do not forget to also set the authentication parameters (or headers).
var clientId = 'apiuser1';
var clientToken = 'fChzVBFn3sdibvRx5xq9BBiabxsR4uhK';
var authParameters = '&clientid=' + clientId + '&clienttoken=' + clientToken;
// Set the desired report and report output format
var templateID = '2551186E-F854-4D1A-ACAE-8ABA02241AE2';
var exportProfileID = 'F8786F1D-CF4D-4B9D-9EB5-A01ED7375A4E';
// Get object with links to exported files (resulttype=pagelinks)
// and serialize as JSON
var formatParameters = 'resulttype=pagelinks&format=json';
// construct complete URL
var apiUrl = host + '/api/v1/report/' + templateID + '/export/' + exportProfileID
+ '?' + formatParameters + authParameters;
// Let jQuery handle the JSONP request (datatype = jsonp):
// and insert all exported files in this page
$.ajax({ url: apiUrl, dataType: 'jsonp', jsonp: 'jsonpCallback' })
.done(function( exportResult ) {
for (var i=0; i < exportResult.FileUrls.length; i++) {
var imgSrc = exportResult.FileUrls[i] + '?' + authParameters; // authParameters are required again!
$('body').append('<img src="' + imgSrc + '" />');
}
})
.fail(function(xhr, textStatus, errorThrown) {
window.alert(object);
});