使用对话框格式上传js

时间:2013-07-17 03:50:53

标签: javascript html upload

我试图从这个脚本html上传文件:

            <form id="addActivity" enctype="multipart/form-data">
            <fieldset>
                <label for="activity">Activity</label>
                <input type="text" name="activity" id="activity" class="text ui-widget-content ui-corner-all" />
                <label for="start_date">Start Date</label>
                <input type="date" name="start_date" id="start_date" class="text ui-widget-content ui-corner-all" />
                <label for="end_date">End Date</label>
                <input type="date" name="end_date" id="end_date" class="text ui-widget-content ui-corner-all" />
                <label for="percentage">Percentage</label>
                <input type="text" name="percentage" id="percentage" class="text ui-widget-content ui-corner-all" />
                <label for="attachment">Attachment</label>
                <input type="file" name="attachment" id="attachment" class="text ui-widget-content ui-corner-all" />
            </fieldset>
            </form>

用于javascript:

    $( "#activity-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Add Data": function() {
                var bValid = true;
                allFields.removeClass( "ui-state-error" );

                    //Ajax Add Barang
                    var dataString = $( "#addActivity" ).serialize();
                    //alert(dataString);

                    $.ajax({
                        type: "POST",
                        url: "add_activity_ajax.php",
                        data: dataString,
                        cache: false,
                        success: function(data){
                            //alert(data);
                            location.reload();
                        }
                    });

                    //Close Dialog Box
                    $( this ).dialog( "close" );

            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            allFields.val( "" ).removeClass( "ui-state-error" );
        }
    });

    $( "#add_new_activity" )
        .button()
        .click(function() {
            $( "#activity-form" ).dialog( "open" );
        });
});

我知道问题是来自html的javascript dosent read enctype =“multipart / form-data”

我应该怎么做javascript读取上传数据? 谢谢你,需要快速回应:((

0 个答案:

没有答案
相关问题