The problem is nothing to do with the
BeginForm
call. It's simply that you're calling jQuery's
html
method, which sets the element's
innerHTML
property; when you do that, the
<script>
elements will be inserted, but
not executed.
javascript - Can scripts be inserted with innerHTML? - Stack Overflow[
^]
To make the scripts execute, you need some additional code:
success: function (result) {
console.log("edit data");
$('.spinner').css('display', 'none');
$('.tab').css('filter', 'blur(0px)');
$("#datasub").empty().html(result);
document.getElementById("datasub").querySelectorAll("script").forEach(script => {
const clone = document.createElement("script")
for (const attr of script.attributes) {
clone.setAttribute(attr.name, attr.value)
}
clone.text = script.innerHTML
script.parentNode?.replaceChild(clone, script)
});
},
NB: Pay attention to the jQuery docs:
jQuery offers several ways to attach a function that will run when the DOM is ready. All of the following syntaxes are equivalent:
$( handler )
$( document ).ready( handler )
$( "document" ).ready( handler )
$( "img" ).ready( handler )
$().ready( handler )
As of jQuery 3.0, only the first syntax is recommended; the other syntaxes still work but are deprecated.
Both of your scripts are using a deprecated syntax, which could be removed in a future version.