在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