- but it only works in IE10+.
Having said that, if you place this in a survey question, I think you may run into problems with the CSRF token, even if you release the session key as shown below.
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
var rpcURL = 'https://pathTo/limesurvey/index.php/admin/remotecontrol';
var params = {
"method": "get_session_key",
"params": {
"username" : "admin",
"password" : "password"
},
id: 1
};
var sessionid;
$.ajax({
url: rpcURL,
method: "POST",
contentType: "application/json",
data: JSON.stringify(params),
dataType : 'json',
error: function(data) {
console.log('error');
},
success: function(data) {
console.log('Success');
console.log(data);
sessionid = data.result;
console.log("Session key: "+sessionid);
var params = {
"method": "export_responses",
"params": {
"sessionkey" : sessionid ,
"surveyid" : "{SID}",
"documenttype" : "json",
"language": null,
"status": "complete",
"sHeadingType": 'code',
"sResponseType": 'short'
},
id: 1
};
$.ajax({
url: rpcURL,
method: "POST",
contentType: "application/json",
data: JSON.stringify(params),
dataType : 'json',
error: function(data) {
console.log('error');
},
success: function(data) {
console.log('Survey Responses:');
console.log(atob(data.result));
// Release the session key
var params = {
"method": "release_session_key",
"params": {
"sessionkey" : sessionid
},
id: 1
};
$.ajax({
url: rpcURL,
method: "POST",
contentType: "application/json",
data: JSON.stringify(params),
dataType : 'json',
error: function(data) {
console.log('error');
},
success: function(data) {
console.log('Key released:');
console.log(data);
}
});
}
});
}
});
});
</script>