Commit f15072dc by Mushtaq Ali

Merge pull request #729 from edx/mushtaq/fix-ora2-ajax-contenttype

Fix jQuery Ajax contentType issue.
parents c5c19786 e0cf4291
...@@ -11,6 +11,8 @@ describe("OpenAssessment.Server", function() { ...@@ -11,6 +11,8 @@ describe("OpenAssessment.Server", function() {
var server = null; var server = null;
var jsonContentType = "application/json; charset=utf-8";
/** /**
Stub AJAX requests. Stub AJAX requests.
...@@ -126,7 +128,8 @@ describe("OpenAssessment.Server", function() { ...@@ -126,7 +128,8 @@ describe("OpenAssessment.Server", function() {
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
url: '/submit', url: '/submit',
type: "POST", type: "POST",
data: JSON.stringify({submission: "This is only a test"}) data: JSON.stringify({submission: "This is only a test"}),
contentType : jsonContentType
}); });
}); });
...@@ -146,7 +149,8 @@ describe("OpenAssessment.Server", function() { ...@@ -146,7 +149,8 @@ describe("OpenAssessment.Server", function() {
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
url: '/cancel_submission', url: '/cancel_submission',
type: "POST", type: "POST",
data: JSON.stringify({submission_uuid: submissionUUID, comments: comments}) data: JSON.stringify({submission_uuid: submissionUUID, comments: comments}),
contentType : jsonContentType
}); });
}); });
...@@ -158,7 +162,8 @@ describe("OpenAssessment.Server", function() { ...@@ -158,7 +162,8 @@ describe("OpenAssessment.Server", function() {
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
url: "/save_submission", url: "/save_submission",
type: "POST", type: "POST",
data: JSON.stringify({submission: "Test"}) data: JSON.stringify({submission: "Test"}),
contentType : jsonContentType
}); });
}); });
...@@ -180,7 +185,8 @@ describe("OpenAssessment.Server", function() { ...@@ -180,7 +185,8 @@ describe("OpenAssessment.Server", function() {
options_selected: options, options_selected: options,
criterion_feedback: criterionFeedback, criterion_feedback: criterionFeedback,
overall_feedback: "Excellent job!" overall_feedback: "Excellent job!"
}) }),
contentType : jsonContentType
}); });
}); });
...@@ -202,7 +208,8 @@ describe("OpenAssessment.Server", function() { ...@@ -202,7 +208,8 @@ describe("OpenAssessment.Server", function() {
options_selected: options, options_selected: options,
criterion_feedback: criterionFeedback, criterion_feedback: criterionFeedback,
overall_feedback: "Excellent job!" overall_feedback: "Excellent job!"
}) }),
contentType : jsonContentType
}); });
}); });
...@@ -226,7 +233,8 @@ describe("OpenAssessment.Server", function() { ...@@ -226,7 +233,8 @@ describe("OpenAssessment.Server", function() {
type: "POST", type: "POST",
data: JSON.stringify({ data: JSON.stringify({
options_selected: options options_selected: options
}) }),
contentType : jsonContentType
}); });
}); });
...@@ -246,7 +254,8 @@ describe("OpenAssessment.Server", function() { ...@@ -246,7 +254,8 @@ describe("OpenAssessment.Server", function() {
data: JSON.stringify({ data: JSON.stringify({
feedback_text: "test feedback", feedback_text: "test feedback",
feedback_options: options, feedback_options: options,
}) }),
contentType : jsonContentType
}); });
}); });
...@@ -279,7 +288,8 @@ describe("OpenAssessment.Server", function() { ...@@ -279,7 +288,8 @@ describe("OpenAssessment.Server", function() {
editor_assessments_order: EDITOR_ASSESSMENTS_ORDER, editor_assessments_order: EDITOR_ASSESSMENTS_ORDER,
allow_file_upload: true, allow_file_upload: true,
leaderboard_show: 15 leaderboard_show: 15
}) }),
contentType : jsonContentType
}); });
}); });
...@@ -293,7 +303,8 @@ describe("OpenAssessment.Server", function() { ...@@ -293,7 +303,8 @@ describe("OpenAssessment.Server", function() {
expect(receivedIsReleased).toBe(true); expect(receivedIsReleased).toBe(true);
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
url: '/check_released', type: "POST", data: "\"\"" url: '/check_released', type: "POST", data: "\"\"",
contentType : jsonContentType
}); });
}); });
......
...@@ -21,6 +21,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -21,6 +21,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
this.element = element; this.element = element;
}; };
var jsonContentType = "application/json; charset=utf-8";
OpenAssessment.Server.prototype = { OpenAssessment.Server.prototype = {
...@@ -149,7 +150,8 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -149,7 +150,8 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: url, url: url,
data: JSON.stringify({submission: submission}) data: JSON.stringify({submission: submission}),
contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
var success = data[0]; var success = data[0];
if (success) { if (success) {
...@@ -184,7 +186,8 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -184,7 +186,8 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: url, url: url,
data: JSON.stringify({submission: submission}) data: JSON.stringify({submission: submission}),
contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(); } if (data.success) { defer.resolve(); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
...@@ -220,7 +223,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -220,7 +223,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
'feedback_options': options 'feedback_options': options
}); });
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ type: "POST", url: url, data: payload }).done( $.ajax({ type: "POST", url: url, data: payload, contentType: jsonContentType }).done(
function(data) { function(data) {
if (data.success) { defer.resolve(); } if (data.success) { defer.resolve(); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
...@@ -263,7 +266,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -263,7 +266,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
submission_uuid: uuid submission_uuid: uuid
}); });
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ type: "POST", url: url, data: payload }).done( $.ajax({ type: "POST", url: url, data: payload, contentType: jsonContentType }).done(
function(data) { function(data) {
if (data.success) { if (data.success) {
defer.resolve(); defer.resolve();
...@@ -307,7 +310,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -307,7 +310,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
overall_feedback: overallFeedback overall_feedback: overallFeedback
}); });
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ type: "POST", url: url, data: payload }).done( $.ajax({ type: "POST", url: url, data: payload, contentType: jsonContentType }).done(
function(data) { function(data) {
if (data.success) { if (data.success) {
defer.resolve(); defer.resolve();
...@@ -348,7 +351,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -348,7 +351,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
options_selected: optionsSelected options_selected: optionsSelected
}); });
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ type: "POST", url: url, data: payload }).done( $.ajax({ type: "POST", url: url, data: payload, contentType: jsonContentType }).done(
function(data) { function(data) {
if (data.success) { if (data.success) {
defer.resolveWith(this, [data.corrections]); defer.resolveWith(this, [data.corrections]);
...@@ -382,7 +385,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -382,7 +385,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
scheduleTraining: function() { scheduleTraining: function() {
var url = this.url('schedule_training'); var url = this.url('schedule_training');
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ type: "POST", url: url, data: "\"\""}).done( $.ajax({ type: "POST", url: url, data: "\"\"", contentType: jsonContentType}).done(
function(data) { function(data) {
if (data.success) { if (data.success) {
defer.resolveWith(this, [data.msg]); defer.resolveWith(this, [data.msg]);
...@@ -406,7 +409,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -406,7 +409,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
rescheduleUnfinishedTasks: function() { rescheduleUnfinishedTasks: function() {
var url = this.url('reschedule_unfinished_tasks'); var url = this.url('reschedule_unfinished_tasks');
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ type: "POST", url: url, data: "\"\""}).done( $.ajax({ type: "POST", url: url, data: "\"\"", contentType: jsonContentType}).done(
function(data) { function(data) {
if (data.success) { if (data.success) {
defer.resolveWith(this, [data.msg]); defer.resolveWith(this, [data.msg]);
...@@ -460,7 +463,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -460,7 +463,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
}); });
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
type: "POST", url: url, data: payload type: "POST", url: url, data: payload, contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(); } if (data.success) { defer.resolve(); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
...@@ -490,7 +493,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -490,7 +493,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
var payload = "\"\""; var payload = "\"\"";
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
type: "POST", url: url, data: payload type: "POST", url: url, data: payload, contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolveWith(this, [data.is_released]); } if (data.success) { defer.resolveWith(this, [data.is_released]); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
...@@ -516,7 +519,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -516,7 +519,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
var url = this.url('upload_url'); var url = this.url('upload_url');
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
type: "POST", url: url, data: JSON.stringify({contentType: contentType}) type: "POST", url: url, data: JSON.stringify({contentType: contentType}), contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(data.url); } if (data.success) { defer.resolve(data.url); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
...@@ -537,7 +540,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -537,7 +540,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
var url = this.url('download_url'); var url = this.url('download_url');
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
type: "POST", url: url, data: JSON.stringify({}) type: "POST", url: url, data: JSON.stringify({}), contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(data.url); } if (data.success) { defer.resolve(data.url); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
...@@ -560,7 +563,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -560,7 +563,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
comments: comments comments: comments
}); });
return $.Deferred(function (defer) { return $.Deferred(function (defer) {
$.ajax({ type: "POST", url: url, data: payload }).done( $.ajax({ type: "POST", url: url, data: payload, contentType: jsonContentType }).done(
function(data) { function(data) {
if (data.success) { if (data.success) {
defer.resolveWith(this, [data.msg]); defer.resolveWith(this, [data.msg]);
......
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