You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

需在#table加载完成后移除#go_back元素的前端技术问题

Fix: Wait for #table Load to Complete Before Removing #go_back

Hey there, let's break down why your current code isn't working and fix it right away!

The Root Problem

Your code calls $('#table').load() which is an asynchronous operation—it doesn't block the rest of your code from running. That means $('#go_back').remove() fires immediately after starting the load request, not after the table has finished loading into the DOM.

The Solution

jQuery's load() method lets you pass a callback function that runs only after the load operation completes successfully. We just need to move the $('#go_back').remove() line into this callback to ensure it waits for the table to be ready.

Modified Working Code

function create_table() { 
  $.ajax({ 
    method: "GET", 
    url: "/api/data/", 
    success: function(data){ 
      // Pass a callback to load() that runs after the table finishes loading
      $('#table').load('http://127.0.0.1:8000/results', function() {
        // This line now executes only when #table is fully loaded
        $('#go_back').remove(); 
      }); 
    }, 
    error: function(error_data){ 
      console.log("errorrr") 
      console.log(error_data) 
    } 
  }) 
}
document.getElementById("create_table").onclick = function() { 
  create_table(); 
  return false; 
}

What Changed?

  • We added a second argument to $('#table').load(): an anonymous function that triggers once the content is successfully loaded into the #table element.
  • The $('#go_back').remove() line is now nested inside this callback, guaranteeing it only runs when the table is fully rendered in the DOM.

内容的提问来源于stack exchange,提问作者barciewicz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:19:55