1

我试图从这个脚本 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 enctype="multipart/form-data"

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

4

0 回答 0