Skip to content
Snippets Groups Projects
Commit 11f147f2 authored by Richard Mathot's avatar Richard Mathot
Browse files

[FIX] survey: prevent pointless AJAX request

Avoid creation of doublon survey_user_input entries when a user loads the landing page of a survey (/survey/start/... route).

Due to some strange spec, jQuery.ajax() function called with "undefined" URL will do an extra call to the URL of the webpage where the script lies (http://api.jquery.com/jQuery.ajax/). Now, we check that URL is not "undefined" to avoid those calls.

By the way, this problem probably happened in every page that had survey.js in its assets... (correct loading of survey.js is fixed in saas-6 at 4dd5dbb2, this fix is complementary.)

This commit fixes #3032 and closes #3337 #3338 #3092.
parent 07ccd6c1
No related branches found
No related tags found
No related merge requests found
......@@ -80,33 +80,37 @@ $(document).ready(function () {
// Pre-filling of the form with previous answers
function prefill(){
var prefill_def = $.ajax(prefill_controller, {dataType: "json"})
.done(function(json_data){
_.each(json_data, function(value, key){
the_form.find(".form-control[name=" + key + "]").val(value);
the_form.find("input[name^=" + key + "]").each(function(){
$(this).val(value);
if (! _.isUndefined(prefill_controller)) {
var prefill_def = $.ajax(prefill_controller, {dataType: "json"})
.done(function(json_data){
_.each(json_data, function(value, key){
the_form.find(".form-control[name=" + key + "]").val(value);
the_form.find("input[name^=" + key + "]").each(function(){
$(this).val(value);
});
});
})
.fail(function(){
console.warn("[survey] Unable to load prefill data");
});
})
.fail(function(){
console.warn("[survey] Unable to load prefill data");
});
return prefill_def;
return prefill_def;
}
}
// Display score if quiz correction mode
function display_scores(){
var score_def = $.ajax(scores_controller, {dataType: "json"})
.done(function(json_data){
_.each(json_data, function(value, key){
the_form.find("span[data-score-question=" + key + "]").text("Your score: " + value);
if (! _.isUndefined(scores_controller)) {
var score_def = $.ajax(scores_controller, {dataType: "json"})
.done(function(json_data){
_.each(json_data, function(value, key){
the_form.find("span[data-score-question=" + key + "]").text("Your score: " + value);
});
})
.fail(function(){
console.warn("[survey] Unable to load score data");
});
})
.fail(function(){
console.warn("[survey] Unable to load score data");
});
return score_def;
return score_def;
}
}
// Parameters for form submission
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment