Accessing `this` in Ajax callback, all within an Object

后端 未结 3 2112
夕颜
夕颜 2020-12-14 12:34

I\'m dealing with a problem about an Ajax callback inside of an Object. Please consider this code :

Search.prototype =
{
    ask : function( query )
    {
           


        
3条回答
  •  时光取名叫无心
    2020-12-14 13:04

    You can use the $.ajax() context object here like:

    $.ajax({
        url : 'http://api.deezer.com/search/track/',
        context: this,
        ...
    }).done(function (res) {
        this.loadResults( res );
    });
    

提交回复
热议问题