html代码:
<form name="formupload" id="formupload" method="post" enctype="multipart/form-data" action="ashx/upload.ashx" >
<input type="file" name="inputfile"/>
<input type="submit" id="btnUpload" value="Press" />
<span id="spmsg"></span>
</form>
上面的代码如果去掉form标签,用JQuery写,该怎么写?
<script language="javascript" type="text/javascript">
        $(document).ready(function() {
        $("#btnUpload").click(function() {
                $.ajax({
                    type: "get",
                    dataType: "html",
                    url: "ashx/upload.ashx",
                    success: function(data) {
                        $("#spmsg").html(data);
                    }
                });
            })
        })
    </script>
这时异步传过去的data是什么啊?
该怎么写?

解决方案 »

  1.   

    data是返回数据,你可以使用alert(data.d)弹出 看看结果是什么。
      

  2.   

    我知道
    我说的是
     $.ajax({
      type: "get",
      dataType: "html",
      url: "ashx/upload.ashx",
    data
      success: function(data) {
      $("#spmsg").html(data);
      }
      });
    这个里面的data
      

  3.   

    那个data是url要传的参数
    data:"id="+id+"&name="+name这样
      

  4.   

    lz的意思是,jquery上传文件吧 应该是,文件名或文件路径
      

  5.   

    lz用JQuery的ajaxFileUpload插件可以试试
    示例:
    function ajaxFileUpload() {
                $("#imgloading")
                .ajaxStart(function() {
                $(this).show(); 
                })
                .ajaxComplete(function() {
                 $(this).hide();
                });
                ;
            $.ajaxFileUpload
        (
    {
        url: '/ashx/upload.ashx',
        secureuri: false,
        fileElementId: 'inputfile',
        dataType: 'json',
        success: function(data, status)//上传成功后操作
        {
            if (typeof (data.error) != 'undefined') {
                if (data.error != '') {
                    $("#spmsg").html(data.error);
                }
            }
            else if (typeof (data.msg) != 'undefined') {
                if (data.msg != '') {
                    window.location.href = data.msg;
                }
            }
        },
        error: function(data, status, e) //有错误时进行操作
        {
            $("#spmsg").html(e);
        }
    }
    )

    return false;
            }
      

  6.   

    引入一个jquery.form插件.
    然后表单上的数据就可以这样取到
    data:$("#defaultForm").formSerialize(),