2
function get_url(){
var returnValue = null;
$.getJSON('http://127.0.0.1:1337/?callback=?&command=get_url', "", function(data){
data = $.parseJSON(data);
returnValue = data[0].get_url;
console.log(returnValue); // "not_null"
});
console.log(returnValue); // "null"
return returnValue;
}
なぜ機能は "NOT_NULL" を返しませんか?
は、どのように私は「NOT_NULL」を返すことができますか? – ExyTab
$ .getJSONへの呼び出しをasync:falseで$ .ajaxの呼び出しに変換します。成功関数のコードが機能します。 –
作業しないでください。 関数get_url(){ \t var returnValue = null; \t $アヤックス({ \t \t URL: 'http://127.0.0.1:1337/?callback=?&command=get_url'、 \t \tデータ型: 'JSON'、 \t \t非同期:偽、 \t \t成功:関数(データ){ \t \t \tデータ= $ .parseJSON(データ); \t \t \tはconsole.log(データ[0] .get_url); \t \t \tのreturnValue =データ[0] .get_url。 \t \t \t} \t}); \t console.log(returnValue); \t return returnValue; } – ExyTab