我有一个页面,它从ajax响应加载它的内容。问题是ajax从我的html页面中的head标签中igonres我的所有脚本。有没有办法让这些javascript文件在我的ajax响应中执行?
AJAX:
$(document).ready(function () {
$(".all").click(function () {
var all = $(this).attr("id");
if (all != '') {
$.ajax({
type: "POST",
url: "php/searchbrowselist.php",
data: "all=" + all,
async: true,
success: function (option) {
var $this = $("#browsemusic")
$this.html(option);
$('#sortable1, #sortable2').sortable({
connectWith: ".connected"
}).disableSelection();
}
});
}
});
});
PHP:
<?php
include ('dbcon.php');
if (isset($_REQUEST['all']) && $_REQUEST['all'] != '') {
// ===============================Button "ALL"====================================
unset($_REQUEST['kw']);
unset($_REQUEST['genre']);
$query = "select * from music";
$result = mysqli_query($link, $query) or die(mysqli_error());
echo '<ul id="sortable1" class="connected">';
while ($info = mysqli_fetch_array($result)) {
echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> ' . $info['artist'] . ' - ' . $info['title'] . ' (' . $info['album'] . ') ' . '</a></div><hr /></li>';
};
echo '</ul>';
}
elseif (isset($_REQUEST['kw']) && $_REQUEST['kw'] != '') {
// ============================= Search for music ================================
$kws = $_REQUEST['kw'];
$kws = mysqli_real_escape_string($link, $kws);
$query = "select * from music where title like '%" . $kws . "%' or artist like '%" . $kws . "%'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
echo '<ul id="sortable1" class="connected">';
while ($info = mysqli_fetch_array($result)) {
echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> ' . $info['artist'] . ' - ' . $info['title'] . ' (' . $info['album'] . ') ' . '</a></div><hr /></li>';
};
echo '</ul>';
}
elseif (isset($_REQUEST['genre']) && $_REQUEST['genre'] != '') {
// =====================================Browse By Genre ===========================================
$genre = $_REQUEST['genre'];
$genre = mysqli_real_escape_string($link, $genre);
$gquery = "select music_id from musicgenre where genre_id = '$genre'";
$results = mysqli_query($link, $gquery) or die(mysqli_error($link));
$music = array();
while ($id_result = mysqli_fetch_array($results)) {
$music[] = $id_result['music_id'];
};
echo '<ul id="sortable1" class="connected">';
foreach($music as $song) {
$query = "select * from music where music_id = '$song'";
$result = mysqli_query($link, $query) or die(mysqli_error());;
while ($info = mysqli_fetch_array($result)) {
echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> ' . $info['artist'] . ' - ' . $info['title'] . ' (' . $info['album'] . ') ' . '</a></div><hr /></li>';
};
};
echo '</ul>';
}
else {
// ================================ Default =========================================
$query = "select * from music";
$result = mysqli_query($link, $query) or die(mysqli_error());
echo '<ul id="sortable1" class="connected">';
while ($info = mysqli_fetch_array($result)) {
echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> ' . $info['artist'] . ' - ' . $info['title'] . ' (' . $info['album'] . ') ' . '</a></div><hr /></li>';
};
echo '</ul>';
};
?>
HTML:
<div id="browsemusic">
<?php include ( 'php/searchbrowselist.php'); ?>
</div>
所以,php文件从ajax获取一些值并将结果加载到我的div中。我还需要它来执行我在头部加载的脚本:
<head>
<script src="js/berniecode-animator.js"></script>
<script src="js/soundmanager2.js"></script>
<script src="js/360player.js"></script>
</head>