Commit 2bcc0065 by Vasyl Nakvasiuk

use ajaxWithPrefix

parent 36c8af61
...@@ -6,24 +6,27 @@ define('WordCloudMain', ['logme'], function (logme) { ...@@ -6,24 +6,27 @@ define('WordCloudMain', ['logme'], function (logme) {
WordCloudMain.prototype = { WordCloudMain.prototype = {
'submitAnswer': function () { 'submitAnswer': function () {
var _this, sendData; var _this, data;
sendData = { data = {
'data': [] 'student_words': []
}; };
_this = this; _this = this;
console.log('submit answer'); console.log('submit answer');
this.wordCloudEl.find('input.input-cloud').each(function(index, value){ this.wordCloudEl.find('input.input-cloud').each(function(index, value){
sendData.data.push($(value).val()); data.student_words.push($(value).val());
}); });
// Send the data to the server as an AJAX request. Attach a callback that will // Send the data to the server as an AJAX request. Attach a callback that will
// be fired on server's response. // be fired on server's response.
$.postWithPrefix( ajaxSettings = {
_this.ajax_url + '/' + 'submit', JSON.stringify(sendData), "data": JSON.stringify(data),
function (response) { "type": "POST",
"contentType": 'application/json; charset=utf-8',
"dataType": 'json',
"success": function (response) {
if ( if (
(response.hasOwnProperty('status') !== true) || (response.hasOwnProperty('status') !== true) ||
(typeof response.status !== 'string') || (typeof response.status !== 'string') ||
...@@ -33,6 +36,11 @@ WordCloudMain.prototype = { ...@@ -33,6 +36,11 @@ WordCloudMain.prototype = {
} }
_this.showWordCloud(response); _this.showWordCloud(response);
} }
};
$.ajaxWithPrefix(
_this.ajax_url + '/' + 'submit',
ajaxSettings
); );
}, // End-of: 'submitAnswer': function (answer, answerEl) { }, // End-of: 'submitAnswer': function (answer, answerEl) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment