Script execution after jQuery Ajax call

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

$.ajax({
    type: "GET",
    url: url,
    dataType: "html",
    success: function(data){
        //.....
   }
 });

After loading the request ajax alert (); The function works, but the someFunction function will not.

$(document).ready(function(){
    alert('TEST'); //this works
    someFunction("#debug",'var');//this doesn't
});

How can I execute this function from an Ajax call

A function executed as <a onclick="someFunction()"will also not work.

+2
source share
2 answers

You should probably use jQuery.getScript to load some javascript from the server and execute it.

: HTML jQuery.ajax. javascript, success. , , ( <script> <head>) ( , jQuery.ajax). , - .

+1

, ajax?

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

,

0

Source: https://habr.com/ru/post/1534396/


All Articles