我有下面的代码在javascript中创建一个类....现在我只会传递“网站”的ID,然后通过ajax调用我将从数据库中获取其余信息(JSON ENCODED)。
现在我唯一的问题是,当我在最后看到对象中的内容时,它只显示 id。
ajax 调用工作正常,因为如果我在成功(ajax)后提醒 this.address,它会显示结果。
我认为我无法使用 ajax 请求设置属性......你能帮忙吗?
function website(id) {
     this.id = id; //id
     $.ajax({  //website_information
      type: "GET",
      url: '/proc.php?proc=website_name&id=' + this.id + '',
      success: function(data){
      var tmp = $.parseJSON(data);
     this.address = tmp.website_address;
     this.name = tmp.website_name;
      }
    });
    }
    var obj = new website('20');
    obj.alertwebsite();
    console.log(obj);