- Posts: 3
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
var params = { "method": "get_session_key", "params": { "username" : "admin", "password" : "test" }, id: 1, jsonrpc: "2.0" }; $.ajax({ url: "https://LimeSurvey/index.php/admin/remotecontrol", type: "POST", contentType: "application/json", data: JSON.stringify(params), error: function(data) { console.log('error'); console.log(data); }, success: function(data) { console.log('success'); console.log(data); } });
Accept */* Accept-Encoding gzip, deflate Accept-Language en-US,en;q=0.5 Content-Length 83 Content-Type application/json; charset=UTF-8 Host 10.0.0.2 Referer https://10.0.0.2/www/ User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0 X-Requested-With XMLHttpRequest POST body: {"method":"get_session_key","params":{"username":"admin","password":"test"},"id":1}
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Connection Keep-Alive Content-Encoding gzip Content-Length 20 Content-Type text/html Date Tue, 19 Mar 2013 15:23:41 GMT Expires Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive timeout=15, max=99 Pragma no-cache Server Apache/2.2.16 (Debian) Vary Accept-Encoding X-Powered-By PHP/5.3.3-7+squeeze15
<script> var params = { "method": "get_session_key", "params": { "username" : "ADD_USER_NAME_HERE", "password" : "ADD_PW_HERE" }, jsonrpc: "2.0", id: 1 }; var sessionid; $.ajax({ url: "https://ADD_YOUR_DOMAIN_HERE.com/index.php/admin/remotecontrol", type: "POST", contentType: "application/json", data: JSON.stringify(params), error: function(data) { console.log('error'); console.log(data); }, success: function(data) { console.log('success'); console.log(data); sessionidarray = JSON.parse(data); sessionid = sessionidarray['result']; console.log("Session key: "+sessionid); var fields = ['id', 'submitdate']; var params = { "method": "export_responses", "params": { "sessionkey" : sessionid , "surveyid" : "{SID}", "documenttype" : "json", "language": null, "status": "complete", "sHeadingType": 'code', "sResponseType": 'short' }, jsonrpc: "2.0", id: 1 }; $.ajax({ url: "https://ADD_YOUR_DOMAIN_HERE.com/index.php/admin/remotecontrol", type: "POST", contentType: "application/json", data: JSON.stringify(params), error: function(data) { console.log('error'); console.log(data); }, success: function(data) { console.log('success'); var jsonoutput =jQuery.getJSON(data); console.log(jsonoutput); } }); } }); </script>
<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>