ajax中的success函數及error函數中使用 $(this)不生效的原因


$('.assess .inputTab .followButton').live('click', function() {
var inputdiv = $(this).parents('.inputTab').find('.inputDiv');
//正確用法:success函數和error函數之外使用$(this)可以獲取到相應的dom元素,在其內部則獲取不到dom元素
 var comment=$(this).parents('.inputTab').parent().find('.contentlist ul');
var istoreview = false;
 if (inputdiv.has('button').length > 0) {
  istoreview true;
 } $.ajax({
    type : "POST",
    url : getRootPath() + "/danymic/publishDanyicReview",
    data : {
     "drw.content" : inputdiv.text()
     // "drw.userId" : inputdiv.attr('data-id'),
     "drw.danymicId" : inputdiv.attr('data-g'),
     "drw.toReviewId" : (istoreview) ? inputdiv.find('button')
       .attr('data-remsg').split(',')[1] : null,
     "drw.toUserId" : (istoreview) ? inputdiv.find('button')
       .attr('data-remsg').split(',')[0] : null
    },
    async : false,
    error : function() {
     alert("網絡服務器異常!");
    },
    success : function(data) {
     if (data.result == 'fail') {
      alert("評論出錯!");
     } else {
     //錯誤用法:$(this).parents('.inputTab').parent().find('.contentlist ul').append("html代碼")
      comment.append(GnDanyReview(data.result));
     }
    }
   }

原文鏈接:https://blog.csdn.net/wj512416359/article/details/37562557


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM