Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 文件上载不在上载按钮上工作_Javascript_Jquery_Asp.net_Jquery Plugins - Fatal编程技术网

Javascript 文件上载不在上载按钮上工作

Javascript 文件上载不在上载按钮上工作,javascript,jquery,asp.net,jquery-plugins,Javascript,Jquery,Asp.net,Jquery Plugins,我正在尝试使用jquery和web处理程序在服务器上上载文件。所有工作正常,但问题是当我点击文件上传控制弹出一个文件选择窗口,我选择文件后,它直接开始文件上传。我的问题是我想在不同控件的单击事件(即按钮单击事件)上上载文件 这是我目前正在使用的代码 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script

我正在尝试使用jquery和web处理程序在服务器上上载文件。所有工作正常,但问题是当我点击文件上传控制弹出一个文件选择窗口,我选择文件后,它直接开始文件上传。我的问题是我想在不同控件的单击事件(即按钮单击事件)上上载文件

这是我目前正在使用的代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.2.6.min.js" type="text/javascript"></script>
    <script src="jquery.ajax_upload.0.6.min.js" type="text/javascript"></script>
    <link href="default.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">
        $(document).ready(function () {

            var button = $('#fuAttachment'), interval;
            $.ajax_upload(button, {
                action: 'FileUploader.ashx',
                name: 'myfile',
                onSubmit: function (file, ext) {
                    if (ext == "jpg") {
                        return true;
                    }
                    else {
                        alert("Invalid File Type.");
                        return false;
                    }
                    //  this.disable();
                },
                onComplete: function (file, response) {
                    window.clearInterval(interval);
                    $('<li></li>').appendTo('.files').text(file);
                }
            });
        });
    </script>
</head>
<body>
<form>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td class="web_dialog_title">
                    <asp:Label ID="Label2" Text="Add Attachment" runat="server"></asp:Label>
                </td>
                <td class="web_dialog_title align_right">

                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAtchTitle" runat="server" Text="Attachment :"></asp:Label>
                </td>
                <td>
                    <input type="file" id="fuAttachment" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAtchType" runat="server" Text="Type :"></asp:Label>
                </td>
                <td>
                    <select id="ddlAtchType" runat="server">
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAttachDesc" runat="server" Text="Description :"></asp:Label>
                </td>
                <td>
                    <textarea id="txtAttachDesc" runat="server" cols="13" rows="4"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <asp:Button ID="btnAddAttach" runat="server" Text="Attach" />
                                <input type="submit" runat="server" name="Submit" value="Submit" id="btnSub" />
                            </td>
                            <td>
                                <input type="reset" value="Reset" id="btnAttachReset" name="Reset" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <ol class="files">
                    </ol>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

$(文档).ready(函数(){
var按钮=$('#fuAttachment'),间隔;
$.ajax_上传(按钮{
操作:“FileUploader.ashx”,
名称:“myfile”,
onSubmit:函数(文件,ext){
如果(外部==“jpg”){
返回true;
}
否则{
警报(“无效文件类型”);
返回false;
}
//这个。disable();
},
onComplete:函数(文件、响应){
窗口。清除间隔(间隔);
$('
  • ).appendTo('.files').text(文件); } }); });

    我希望我的上传过程应该在
    btnSub
    click事件开始。如果有人知道,请帮助我……。

    您可以使用jquery uploadify


    我不了解asp.net,但在html
    form
    标记中,您应该使用
    enctype=“multipart/form data”