0

执行一个基本的 AJAX 请求,但是当显示 HTML 时,没有 HTML 链接起作用,现在 CSS:hover 元素也起作用。

对我做错了什么感到困惑。这是下面的代码示例。

CSS:

li:hover{ background:red; }
a{ text-decoration:none; }
a:hover{ text-decoration:underline; }

HTML (index.php):

<script>
$(document).ready(function(){
    ajax();
});
</script>
<ul class="loadhere"></uL>

加载this.php:

<li><a href="">Example</a></li>

JS(阿贾克斯):

function ajax(){
$.ajax({
    type:"POST",
    url:"http://example.com/loadthis.php",
    dataType: "html" 
})
.done(function(result){
    $('ul.loadhere').html(result);      
});
}
4

2 回答 2

1

您需要使用 ajax 函数的“success”选项,取下 done 函数并将函数插入 ajax 对象中的 success 选项中,如下所示:

function ajax(){
    $.ajax({
        type:"POST",
        url:"http://example.com/loadthis.php",
        dataType: "html" ,
        success: function(result){
            $('ul.loadhere').html(result);      
        }
    });
}
于 2013-05-23T10:24:10.067 回答
0

尝试这个

 <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>
于 2013-05-30T12:59:42.573 回答