Access json data outside of $.getJSON()

后端 未结 3 1933
南笙
南笙 2021-01-02 22:48
$(document).ready(function () {
    var value = getParmsVals()[\"search\"];
    $.getJSON(\'/api/search/GetQuestionByKey/\' + value, function (jsonData) {
        $(         


        
3条回答
  •  孤街浪徒
    2021-01-02 22:53

    You can also put your variable on the object and use .bind(), like so:

    this.fullname = "default";
    
    $.getJSON('/api/search/GetUserById/' + userId, function (jsonData) {
       this.fullname = jsonData.firstname + " " + jsonData.lastname;
    }.bind(this));
    

提交回复
热议问题