18910140161

JavaScript-如何正确使用刷新div?-堆栈溢出

顺晟科技

2022-10-19 13:42:26

135

嗨,

你能解释为什么我的刷新div不起作用吗?当单击submit时,看起来div试图通过删除所有行数据来刷新,但它不会返回任何东西,而是将div留空。存储到DB的数据很好,但我需要div刷新并显示所有新提交的数据

$('#submitBtm').on('click', onSubmit = () => {

    const first_nameV = document.getElementById("first_name").value;
    const last_nameV = document.getElementById("last_name").value;
    const emailV = document.getElementById("email").value;
    const departmentV = document.getElementById("department").value;
        
        $.ajax({
            type: "POST",
            url: `companydirectory/libs/php/insertAll.php?first_name=${first_nameV}&last_name=${last_nameV}&email=${emailV}&departmentID=${departmentV}`,
            success: function(data) {
               
            },
            error:  function(request,error) {
                console.log(request)                                   
            }
        })

        $("#id_data").load(location.href + " #id_data");

    event.preventDefault();
})

在HTML页上

$('#submitBtm').on('click', onSubmit = () => {

    const first_nameV = document.getElementById("first_name").value;
    const last_nameV = document.getElementById("last_name").value;
    const emailV = document.getElementById("email").value;
    const departmentV = document.getElementById("department").value;
        
        $.ajax({
            type: "POST",
            url: `companydirectory/libs/php/insertAll.php?first_name=${first_nameV}&last_name=${last_nameV}&email=${emailV}&departmentID=${departmentV}`,
            success: function(data) {
               
            },
            error:  function(request,error) {
                console.log(request)                                   
            }
        })

        $("#id_data").load(location.href + " #id_data");

    event.preventDefault();
})

顺晟科技:

它不会更新,因为您没有追加在成功回调时收到的新数据

$('#submitBtm').on('click', onSubmit = () => {

    const first_nameV = document.getElementById("first_name").value;
    const last_nameV = document.getElementById("last_name").value;
    const emailV = document.getElementById("email").value;
    const departmentV = document.getElementById("department").value;
        
        $.ajax({
            type: "POST",
            url: `companydirectory/libs/php/insertAll.php?first_name=${first_nameV}&last_name=${last_nameV}&email=${emailV}&departmentID=${departmentV}`,
            success: function(data) {
               
            },
            error:  function(request,error) {
                console.log(request)                                   
            }
        })

        $("#id_data").load(location.href + " #id_data");

    event.preventDefault();
})
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航