I am having troubles with getting script from an external HTML file. I have a file page1.php that sends AJAX requests to page2.php to get the following things:
- several div elements to append them to page1.php
- get jQuery code to append and execute it in page1.php
Point 1 works well. I am getting the divs and appending them to page1.php. Point 2 doesn't work yet. The thing is that the JS code from page2.php has some dynamic elements so I cannot simply hardcode the JS code in page1.php. Is there even a way to get inline JS with jQuery from an external HTML file, append it to the current file and execute it? If yes, how would you do this?
Here is the ajax code that requests the divs. As I said, it works well. I'm just having questionmarks on how to get the inline JS from page2.php into page1.php and execute it.
Page1.php
$('.option-box').on('click', function () {
var path = $(this).data('path');
$.ajax({
type: 'GET',
url: path,
success: function (html) {
var desktop_summary = $(html).find('div#desktop-summary-div').html();
$('#desktop-summary-div').html(desktop_summary);
var mobile_summary = $(html).find('div#mobile-summary-div').html();
$('#mobile-summary-div').html(mobile_summary);
var option_content = $(html).find('div#config-content').html();
$('#last-element-before-footer').before(option_content);
OnloadFunction();
}
});
});
Page2.php
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div id="desktop-summary-div">some content</div>
<div id="mobile-summary-div">some content</div>
<div id="config-content">some content</div>
<script>
some script that needs to be executed in the page1.php
</script>
</body>
</html>
Thansk a lot!