[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 4dd5dbb28974b3f0d9cbcc9b502aab2d83b5e6f3, this fix is complementary.) This commit fixes #3032 and closes #3337 #3338 #3092.
This commit is contained in:
parent
07ccd6c1c7
commit
11f147f2d9
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue