Why does jQuery.getJSON return no data?

I have this method: function getUserName(guid) { var name = "Unbekannt"; $.getJSON(urlCurrent, { "method" : "get_user_info", "guid" : guid, "auth_token" : temporaryAuthToken }, function(data) { if (data.status == 0) { alert(data.result[0].name); name = data.result[0].name; } }); return name; } Nearly all is working: the Ajax-Request gets data and fires the callback-function, so that alert(data.result[0].name); shows a popup with this value: "Forename Surname" But then at return name; the method returns "Unbekannt", although name should have the new value "Forename Surname". What happened and where´s the mistake? Thx a lot
The call to getJSON is asynchronous. So, at the return name; the data probably won't have arrived yet.

以上就是Why does jQuery.getJSON return no data?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准