Jquery AJAX:加载HTML、CSS链接不起作用
执行一个基本的AJAX请求,但是当显示HTML时,没有HTML链接起作用,现在CSS:hover元素也起作用 对我做错了什么感到困惑。下面是一个代码示例 CSS: HTML(index.php): 您需要使用ajax函数的“success”选项, 取下done函数并在ajax对象中插入函数in success选项, 像这样:Jquery AJAX:加载HTML、CSS链接不起作用,jquery,html,css,ajax,post,Jquery,Html,Css,Ajax,Post,执行一个基本的AJAX请求,但是当显示HTML时,没有HTML链接起作用,现在CSS:hover元素也起作用 对我做错了什么感到困惑。下面是一个代码示例 CSS: HTML(index.php): 您需要使用ajax函数的“success”选项, 取下done函数并在ajax对象中插入函数in success选项, 像这样: function ajax(){ $.ajax({ type:"POST", url:"http://example.com/loa
function ajax(){
$.ajax({
type:"POST",
url:"http://example.com/loadthis.php",
dataType: "html" ,
success: function(result){
$('ul.loadhere').html(result);
}
});
}
试试这个
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script>
$(function(){
ajax();
function ajax(){
$.get('loadthis.php', {}, function(){
}).done(function(result){
$('ul.loadhere').html(result);
});
}
});
</script>
$(函数(){
ajax();
函数ajax(){
$.get('loadthis.php',{},function(){
}).完成(功能(结果){
$('ul.loadhere').html(结果);
});
}
});
result看起来如何?路径可能是相对于example.com/loadthis.php的,因此它找不到css文件。您可以将路径更改为绝对路径,因此对于CSS来说,例如:如果您现在不考虑ajax,只需在列表中添加一个
,CSS是否可以做到这一点?提供的代码可以做到-正如@Andreas所说,这应该可以做到。。。除非你是跨域的!不幸的是,仍然没有运气。
<li><a href="">Example</a></li>
function ajax(){
$.ajax({
type:"POST",
url:"http://example.com/loadthis.php",
dataType: "html"
})
.done(function(result){
$('ul.loadhere').html(result);
});
}
function ajax(){
$.ajax({
type:"POST",
url:"http://example.com/loadthis.php",
dataType: "html" ,
success: function(result){
$('ul.loadhere').html(result);
}
});
}
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script>
$(function(){
ajax();
function ajax(){
$.get('loadthis.php', {}, function(){
}).done(function(result){
$('ul.loadhere').html(result);
});
}
});
</script>