Last active
November 15, 2016 13:21
-
-
Save Anan5a/3b698481630843a49564f6a195ccc185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
function loadjson(url,lang,next){ | |
var j; | |
if(next<=0||next=='undefined'){ | |
next='null'; | |
} | |
$.ajax({ | |
url:url, | |
type:'POST', | |
data:{lang:lang,next:next}, | |
success:function(e){ | |
j=e; | |
}, | |
dataType:'json' | |
}); | |
return j; | |
} | |
$('#tt').click(function(){ | |
var c=loadjson('/getLang.php','english',-1); | |
console.log(c); | |
tpl(c); | |
}); | |
function tpl(jdata){ | |
var tpl; | |
console.log(jdata); | |
tpl = '<div class="form-group">'; | |
tpl += '<label><span class="label label-danger">English</span> '+jdata._default+'</label>'; | |
tpl += '<br/>'; | |
tpl += '<label><span class="label label-success">Key</span> '+jdata.key+'</label>'; | |
tpl += '<div class="bg-warning" id="_'+jdata.key+'"><p class="to-translate"></p></div>'; | |
tpl += '</div>'; | |
$('#tform').append(tpl); | |
} | |
}); | |
/* | |
*/ |
still not working :(
$(document).ready(function(){
function loadjson(url,lang,next){
if(next<=0||next=='undefined'){
next='null';
}
$.ajax({
url:url,
type:'POST',
data:{lang:lang,next:next},
success:function(data){
tpl(data);
},
dataType:'json'
});
}
$('#tt').click(function(){
//var c = loadjson('/getLang.php','english',-1);
//tpl(c);
// loadjson function does a ajax function. Generally ajax
// function can not return anything, if the ajax call is asynchronius.
// In that case you need to do in success call back.
loadjson('/getLang.php','english',-1);
});
function tpl(jdata){
var tpl = "";
console.log(jdata);
tpl = '<div class="form-group">';
tpl += '<label><span class="label label-danger">English</span> '+jdata._default+'</label>';
tpl += '<br/>';
tpl += '<label><span class="label label-success">Key</span> '+jdata.key+'</label>';
tpl += '<div class="bg-warning" id="_'+jdata.key+'"><p class="to-translate"></p></div>';
tpl += '</div>';
$('#tform').append(tpl);
}
});
- set header content type to json
or - use parse json in javascript
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function loadjson doesn't return anything