确认你的 js 部分与样例文件没有大的出入先检查文件确实非上传了
exit(json_encode($_FILES));

解决方案 »

  1.   

    是不是js脚本有报错啊,你在firebug控制台下看有不有报错。
      

  2.   

    完全代码:
    上传文件表单upfileForm.php<!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk"><link href="../css/manager.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="../js/jquery.js"></script>
    <script src="../js/ajaxfileupload.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/jrosion.js"></script> <script type="text/javascript">
    $(document).ready(function(){
     
    }); function upload(){
    $.ajaxFileUpload({
                    url: 'upfile.php', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议,一般设置为false
                    fileElementId: 'fileToUpload', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data, status)  //服务器成功响应处理函数
                    {
                        alert(data.msg);
                        //$("#img1").attr("src", data.imgurl);
                        if (typeof (data.error) != 'undefined') {
                            if (data.error != '') {
                                alert(data.error);
                            } else {
                                alert(data.msg);
                            }
                        }else{
                         alert("upload file failure!");
                        }
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                    }
    });
    return true;
    }
    </script><title>网站栏目管理</title>
    </head>
    <body><!-- <form action="upfile.php" method="post" enctype="multipart/form-data"> -->
    <input type="file" id="fileToUpload" size="40" name="fileToUpload">
    <button type="button" id="buttonUpload" onclick="return upload();">上传</button>
    <!-- </form>--></body>
    </html>上传文件服务端upfile.php<?phpheader("Content-type: text/html; charset=utf-8");$upFilePath = "../userUploadDatas/". $_SESSION ["userId"]."/";$res ["error"] = ""; // 错误信息
    $res ["msg"] = ""; // 提示信息
    if (@move_uploaded_file(@$_FILES ["fileToUpload"] ["tmp_name"], $upFilePath .@$_FILES ["fileToUpload"] ["name"])) {
    $res ["msg"] = "ok";
    } else {
    $res ["error"] = "error";
    }echo json_encode ( $res );
    死活不能AJAX上传啊, 直接<form action="upfile.php" method="post" enctype="multipart/form-data"> -->
    <input type="file" id="fileToUpload" size="40" name="fileToUpload">
    <button type="button" id="buttonUpload" onclick="return upload();">上传</button>
    </form>
    文件是可以上传的,我就不清楚了,我上面的代码怎么写才能AJAX上传文件,郁闷几天了,,不知道原因。。
      

  3.   

    先去掉
    <script type="text/javascript" src="../js/jrosion.js"></script>
    看看,可能有冲突
      

  4.   

    老大,已将jrosion.js去掉,效果一样。。
      

  5.   

    你在 upfile.php 中只写
    <?php
    echo '{"msg":"hello"}';
    试试
    注意一定不要有 BOM 头
      

  6.   

    我受不了, 下载了一个错误的ajaxfileupload.js文件, 最后在CSDN下载了一个,没有问题, 我郁闷的不行,好像是在官网下载的。