how to execute ajax output script

后端 未结 5 434
故里飘歌
故里飘歌 2021-01-20 11:02

I\'m getting an ajax output success data.

Where the data contains some html text and a script.

But the script is not executing, how can I execute the script.

5条回答
  •  不要未来只要你来
    2021-01-20 12:05

    Interestingly enough, I use jQuery and using the html() function was enough to get the JavaScript to execute. So more or less I had nothing special to do.

    There is a simplified version:

    var myform = $('form#form-id');
    $.post(myform.attr('action'), myform.serialize(), function(response) {
      $('#some-id').html(response.message);
    }
    

    In my case the code kicked in automatically so I did not need any other of the solutions proposed here.

提交回复
热议问题