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 答疑

评论 抢沙发

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

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

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏