executing script after jQuery Ajax Call

前端 未结 2 503
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 19:22

I load some HTML code into a div with the .load function af jQuery that contains some code I want to execute;

$.ajax({
    type: \"GET\",
    url: url,
    dataT         


        
相关标签:
2条回答
  • 2021-01-21 20:02

    Probably you should use jQuery.getScript to loading some javascript from the server and execute it.

    UPDATED: In the most cases one load only the pure HTML fragment with respect of jQuery.ajax. Binding of elements to some javascript functions one do inside of success handle. All functions which one use in any event handler one loaded before (with <script> in the <head> block) on the main page (on the page which call jQuery.ajax). Then all look very clear and dynamic loading of any scripts is not needed.

    0 讨论(0)
  • 2021-01-21 20:18

    Why wouldn't you use the callback function that's already available in your ajax call?

    $.ajax({
    type: "GET",
    url: url,
    dataType: "html",
    success: function(data){
        alert('TEST'); //this works
        someFunction("#debug",'var');//this doesn't
    }});
    

    I would take a closer look at how you are architecting the code

    0 讨论(0)
提交回复
热议问题