最好贴源码,我写程序不知道怎么回事,读都读不出文本的内容 ,代码如下:$(document).ready(function() {
    $("#txtconfirm").click(function() {
        $.ajax({
            url: 'test.txt',
            dataType: 'text',
            success: function(data) {
                alert(data);
            }
        });
    });
});

解决方案 »

  1.   

    看看url文件有没有,id=txtconfirm这个有没有
      

  2.   


    初步估计是你的引用jQuery包有问题<html><head>
    <title>jQuery Ajax 实例演示</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </head>
    <script src="http://code.jquery.com/jquery-1.4.3.js"></script>
    <body><div id="result" style="background:orange;border:1px solid red;width:300px;height:200px;"></div>
    <form id="formtest" action="" method="post">
    <span id="success" > </span>
    </form>
    <script type="text/javascript">$.ajax({
       type: "POST",//请求方式
       url: "java.txt",//地址,就是action请求路径
       data: "text",//数据类型text xml json  script  jsonp
       success: function(msg){//返回的参数就是 action里面所有的有get和set方法的参数
           document.getElementById("result").innerHTML=msg;
       }
    }); 
    </script>
    </body>
    </html>
      

  3.   

    $(document).ready(function() { // 是否导入了jQuery
        $("#txtconfirm").click(function() { //id=txtconfirm的元素是否存在
            $.ajax({
                url: 'test.txt', // url路径是否正确
                dataType: 'text',
                success: function(data) {
                    alert(data);
                }
            });
        });
    });
      

  4.   

    <html>
    <head>
    <script type="text/javascript" src="js/jquery-1.5.1.js"></script>
    <script>
    $(document).ready(function() {
        $("#txtconfirm").click(function(){
            $.ajax({
            url: 'test.txt',
            dataType: 'text',
            error: function(xhr) { alert( xhr.responseText ); }, //如果你的url,txt有问题,将会提示
            success: function(data) {
                alert(data);
            }
            });
        });
    });
    </script>
    </head><body>
    <div id="txtconfirm">sss</div> ---id要正确
    </body>
    </html>
      

  5.   


    <html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    </head>
    <body>
        .<title></title>    <script type="text/javascript" src="Default2_files/jquery-1.7.1.min.js"></script>    <script type="text/javascript">        $(document).ready(function() {            $("#txtconfirm").click(function() {                $.ajax({                    url: 'test.txt',                    dataType: 'text',                    error: function(xhr) { alert(xhr.responseText); },                    success: function(data) {                        alert(data);
                        }
                    });
                });
            });
        </script>    <div>
            <input style="width: 200px;" id="txtContent" type="text"><input id="txtconfirm" value="确定"
                type="button"></div>
    </body>
    </html>
    路径没错
      

  6.   

    test.txt 有值么?<script type="text/javascript">
            $(document).ready(function() {
                $("#txtconfirm").click(function() {
                    $.ajax({
                        url: 'test.txt',
                        dataType: 'text',
                        error: function(xhr) { alert("error: " + xhr.responseText); },
                        success: function(data) {
                            alert("success: " + data);
                        }
                    });
                });
            });
        </script>如果是"succcess: ", 看txt文件内容是否为空。
      

  7.   

    代码本机测试没有问题。copy 你的代码到本机测试的。本机有可能和你有区别的地方是:<script type="text/javascript" src="js/jquery-1.5.1.js"></script>html 和 test.txt 同为utf-8格式(其实测试过不同格式文档,没发现有错误。)
      

  8.   

    更多其他.net技术和jquery,css技术  欢迎访问:www.cnntec.com
      

  9.   

    好了,我都不知道怎么回事,,发给您楼上 hanqinsky这姐们一份,没见她怎么该,就好了,结贴了,谢谢大家了,我自己看看