0

我正在使用 laravel 和 ajax 请求。回电后,我将更新的信息提取到我的输入表单中

<a data-post-table-id="1" data-post-id="55" id="greenButtonForm1" data-post-color="#80c87d" data-post-title="6346" href="javascript:PopUpShowEdit(1)">
   <i class="fas fa-adjust" style="color:green;" aria-hidden="true"></i>
</a>

但是当我在浏览器的控制台中编写时:

$("#greenButtonForm1").data();

我在更新页面之前得到了我以前的数据

postTitle: 6346
postColor: "#ff464a"
postId: 55
postTableId: 1
__proto__: Object

我不知道为什么 jQuery 不想获取正确的信息:

function PopUpShowEdit(x) {
   $("#popup").css('display',"block");
   var total;
   total = $("#greenButtonForm"+x).data();
   $("#color").val(total.postColor);
   console.log(total);
   $("#break_post_id").val(total.postId);
   $("#id_of_post_table").val(total.postTableId);
   $("#description").val(total.postTitle);
   console.log(total.postColor);
}

这是ajax请求的结束

success:function(response) {
   console.log(response);
   $("#redButBreak"+ post_id).css('display',"none");
   $("#greenButBreak"+ post_id).css('display',"block");
   console.log("CREATING" + post_id);
   const listItem = document.querySelector("#greenButBreak"+post_id);
   const newItem = document.createElement('td');
   newItem.innerHTML = '<a data-post-id="'+response[0]+'"  id="greenButtonForm'+response[3]+'" data-post-color="'+response[2]+'" data-post-title="'+response[1]+'" href="javascript:PopUpShowEdit('+response[3]+')"><i class="fas fa-adjust" style="color:green;"></i></a> ';
   listItem.parentNode.replaceChild(newItem, listItem);
}
4

0 回答 0