這是我的理解,eval()更可能是最好的選擇。但在我的inserttest.php頁面中,它是html和javascript的混合體。當頁面加載完成並將內容放入#light Div時,只有javascript不起作用。返回可執行的Javascript和帶負載的html內容()
所以我的問題是......下面是最好的方法。我怎麼去編輯它以允許所有內容按原樣返回。
<script type="text/javascript">
$(document).ready(function(){
$("form#myform").submit(function(event){
$('#light').load('inserttest.php');
});
});
</script>
我在這個線程[Run script tags loaded with ajax
eval($('#container script').html());
我相信這將只返回腳本並沒有HTML /看見
更新 - insertest.php的輸出
<form id="myformshareid" method="POST" class="form_statusinput">
<input type="hidden" name="toid" id="toid" value="<? echo $user1_id ?>">
<input type="hidden" name="streamitem_con" id="streamitem_con" value='<? echo $streamitem_data['streamitem_content'] ?>'/>
<input type="hidden" name="streamitem_idsharetype" id="streamitem_idsharetype" value="<? echo $noterypes['streamitem_type_id'] ?>">
<input type="hidden" name="streamitem_id" id="streamitem_id" value="<? echo $streamitem_data['streamitem_id'] ?>">
<div cols="40" rows="5" name="newmsg" id="newmsg" data-ph="Say something <? echo $data['first']; ?>..." contenteditable="true"></div>
<select id="privacy" name="privacy">
<option value="1">Public</option>
<option value="2">Friends</option>
</select>
<select id="comments" name="comments">
<option value="1">Comments On</option>
<option value="2">Comments Off</option>
</select>
<input title="Share <? echo $data["fullname"] ?>'s ststus to your wall" style="cursor:pointer;color:#FFF;" type="submit" id="button" value="Share">
</form>
<div id="display"></div>
<script type="text/javascript">
$(function(){
$('.pop').unbind().click(function() {
var streamitem_id = $(this).attr('id');
$.ajax({
type:"POST",
url: "sharecollect.php",
data: { streamitem_id: streamitem_id, },
success: function(data) {
$('.pop').css('overflow-y', 'auto');
$('body').css('overflow', 'hidden');
$("#sharecontent"+streamitem_id).html(data);
}
});
return false;
});
});
</script>
您可以使用'。.getScript()'...使用GET HTTP請求從服務器加載JavaScript文件,然後執行它。 –
正如此線程所述? [link] http://stackoverflow.com/questions/14521108/dynamically-load-js-inside-js) –
取決於如何在'inserttest.php'中設置腳本。重要的是要明白'document.ready'已經出現在主頁面中。 'eval()'在html上不起作用 – charlietfl