Lire un fichier json hors getJson
Bonjour à tous,
J'ai mis un fichier json qui comprend des variables, et je veux lire quelques variables hors de getJson:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
$.ajaxSetup({
async: false
});
/*
Code ici
*/
var minChars;
var maxChars;
var reg;
var userChars;
var userRegex;
$.getJSON( "http://v1.bonneoccasion.ma/Tests/json/JsPHP/Translate/translate_"+setLang+".json", function( data ) {
$.each(data, function(ind,val){
//console.log(ind);
console.log(val);
console.log(val[fieldName]);
if(val[fieldName] != undefined){
//console.log(val[fieldName]['vars']);
userChars = val[fieldName]['chars'];
userRegex = val[fieldName]['regex'];
// Set variables for error messages (JS/jQueryVars.js)
minChars = val[fieldName]['vars']['minChars']; // minimum characters
maxChars = val[fieldName]['vars']['maxChars']; // maximum characters
reg = val[fieldName]['vars']['regex']; // accepted regex
}
//console.log(val.allowed);
//console.log(showInfo);
}); // end DOM
}); // end DOM
console.log('min is '+minChars);
console.log('userchars '+userChars);
console.log('userregex '+userRegex);
console.log('reg'+reg); |
Au consol, je reçois:
Code:
1 2
|
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. |
C'est quoi la méthode pour éviter cette erreur, j'ai du mal qu'il fonctionnerait plus après quelques temps, et je me trouverais à tous changer.
Merci à vous