在CMS環境中實現此代碼時。獲取beloe錯誤。AJAX調用outerHTML uncaught typeError
遺漏的類型錯誤:無法未定義
誰能幫我的讀取屬性「outerHTML」來解決這個問題?
在此先感謝
main.html中:
<div class="pwrapper">
<select name="country" id="scountry">
<option id="EN" value="global.html">GLOBAL, ENGLISH</option>
<option id="AU" value="australia.html">AUSTRALIA</option>
</select>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('.country #scountry').on('change', function(e){
var ajaxURL = $(this).val();
$.ajax({
url: ajaxURL,
success: function(data) {
var htmlData = $(data);
$('#scontainer').html(htmlData.filter('#ajax-container').get(0).outerHTML);
}
});
});
$('.countrySelector #scountry').trigger('change');
});
</script>
</div>
<div class="wrapper">
<section class="no-padding">
<div id="scontainer">
</div>
</section>
</div>
global.html(在main.html中的子頁面):
<div id="ajax-container">
Hello World!!
</div>
不'$(「#scontainer」)HTML (數據);'工作? – lshettyl
你不需要outerHTML ...只需插入jQuery對象。如果它是返回的根的唯一元素...插入'data'並且不需要過濾 – charlietfl