jQuery方法链接问题访问此内部道具

时间:2020-03-09 07:50:22

标签: javascript jquery ajax

我正在尝试设置一组方法,但是我无法访问jQuery post函数中的属性

我无法通过jquery post函数访问此当前对象

我在下面的代码中添加了我想要的////

注释
  var ajaxFunction = {
    targetDiv: $("#site-content"),
    nextblog:'2',  // its just a number
    getPost:function(url){
      var admin_url = url;
      var data = {action: 'next_post_ajax',nextpost:this.nextblog};      
      jQuery.post(admin_url, data, function(response) {
        response=JSON.parse(response);
        ajaxFunction.renderPost(response)  //// wanna replace ajaxFunction.renderPost with this.renderPost
        ajaxFunction.nextblog=response.next_post;  //// wanna replace ajaxFunction.nextblog with this.nextblog
      }); 
       return this;
    },
    renderPost:function(data){
     var div = ` <div class="post-box">
     <h2>${data.post_title}</h2>
     <img src="${data.feautred_image}">
     ${data.post_content}

     </div>`

      this.targetDiv.append(div);
       return this;
   }
 }

0 个答案:

没有答案