0

Here is the code:

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
</head>

<body>
<div class ="click"> Click me <div>
<div class = "file"></div>

<script>


$(document).ready(function(){

    $(".click").click(function(){

        $.ajax({

            beforeSend: function(){
            $(".file").html('<img src="a.gif" alt="Smiley face" height="42" width="42">' )
            },
            url: 'a.txt',
            type: "GET",
            data: ({

            "id" :  0       
            }),                 
            success:function(results){
                console.log("inside success");
                $(".file").html('results');
            }   

        });

    });
});

</script>
</body>
</html>

Here problem is that success:function never calls up...I am not getting any results..just the spinner...my a.txt file is in same folder as this html is. the content of a.txt is <br> Hello world <br>.

4

1 回答 1

0
$(".click").click(function(){

    $.ajax({

        url: 'a.txt',
        type: "get",
        data: "id=" + 0,                 
        success:function(results){
            console.log("inside success");
            $(".file").html(results);
        },
        beforeSend: function(){
            $(".file").html('<img src="a.gif" alt="Smiley face" height="42" width="42">' );
        }

    });

});

...如果这不起作用,我会感到惊讶...当类“文件”被多次使用时,很难将类选择器与 .html() 一起使用可能会导致可怕的错误

于 2013-09-09T15:38:43.897 回答