Load scripts after AJAX loads content?

安稳与你 提交于 2019-12-04 16:49:51

Not sure I really get the question, but to load a script after the content is loaded with Ajax you could do something like this:

$.ajax({
  url: url,
  data: data,
  success: function() {
     //success loading content
  },
  error: function() {
    //error loading content
  },
  complete: function() {
     $.getScript("/scripts/mysearchscript.js", function() {
          alert('loaded script and content');
     });
  }
});

"If .ready() is called after the DOM has been initialized, the new handler passed in will be executed immediately." - http://api.jquery.com/ready/

EDIT

I think I may have misinterpreted your question, sorry. Are you saying that the search tries to search before the table is fully loaded? I thought you were trying to search before the page had completed loading. Have you tried using a callback function attached to your .load(), or just after container.append()?

after load

$('#content').load(url,callSearchFunction());

you can do it much simpler after append

 container.append(justTable);
 callSearchFunction();
$('.container').load('yourPage.html',function(){          
    //Do whatever you want here              
});

You can pass an anonymous function like a parameter on the jquery method .load()

http://api.jquery.com/load/

That function will execute when the ajax request is complete

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!