我的应用需要静态翻译。我已经在json文件中输入了翻译。我想在加载js文件之前加载这个json文件。我该怎么做?任何帮助,将不胜感激。
我个人不依赖于订单,脚本被加载到文档中,但是使用像domready-event这样的机制,甚至更像require.js。使用require.js,你可以加载你的JSON,之后做你的JS东西。
domready-event:https://learn.jquery.com/using-jquery-core/document-ready/
require.js:requirejs load static JSON file
你可以这样做:
$(function(){
$.ajax({
dataType: "json",
url: 'path/to/json/file.json',
success: function(result){
start(result)
}
});
});
function start(data /*converted to javascript object*/ ){
// you can process the JSON result first
// and call other functions after this point
}
$(function(){
$.ajax({
dataType: "json",
url: 'path/to/json/file.json',
success: function(result){
// you can process the JSON result first
// and call other functions after this point
}
});
});