输入数据不变。阿贾克斯

时间:2020-09-27 22:47:57

标签: javascript jquery ajax

我正在使用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);
}

0 个答案:

没有答案
相关问题