Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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/9/javascript/478.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
Php 如何从具有多个div和多个动态元素的表单发送文件和数据,如下所示?_Php_Javascript_Jquery_Html_Forms - Fatal编程技术网

Php 如何从具有多个div和多个动态元素的表单发送文件和数据,如下所示?

Php 如何从具有多个div和多个动态元素的表单发送文件和数据,如下所示?,php,javascript,jquery,html,forms,Php,Javascript,Jquery,Html,Forms,JavaScript: $("#selectButton").live("click", function () { $("#selectedFile").live("change", function () { //var inp = document.getElementById('selectedFile'); files = document.getElementById('selectedFile').files; $("#son

JavaScript:

$("#selectButton").live("click", function () {
    $("#selectedFile").live("change", function () {
        //var inp = document.getElementById('selectedFile');
        files = document.getElementById('selectedFile').files;
        $("#songs-sec table").html('');
        $("#songs-sec table").append('<tr><th>Track No</th><th>Song Title</th><th>Artists</th><th>Creation On</th></tr>');
        for (var i = 0; i < files.length; ++i) {
            var name = files.item(i).name;
            var size = files.item(i).size;
            var type = files.item(i).type;
            var file = files.item(i);
            if (type == "audio/mpeg") {
                $("#songs-sec table").append('<tr><td><input style="width: 20px; font-size:12px;padding: 3px;" type="text" class="trackno" name="trackno[]" value="' + (i + 1) + '" /></td><td style="width: 80px; font-size:12px;padding: 3px;"><input style="padding: 3px;" type="text" class="song" name="song[]" value="' + name + '" /></td><td><input style="padding: 3px;" type="text" class="art" name="artist[]" /></td><td><input style="width: 70px;padding: 3px;" type="text" class="creationdate" name="creationdate[]" /></td></tr>');
            } else if (type == "image/jpeg") {
                cnt = i;
                readFile(cnt);
            }
        }
        $("#songs-sec table").append('<tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td><input type="submit" id="uploadButton" name="upload" value="Upload" style="border:none;height: 42px; color: #fff;background: -moz-linear-gradient(center top , rgb(58, 166, 227) 0px, rgb(46, 160, 225) 51%, rgb(24, 153, 226) 100%) repeat scroll 0% 0% transparent;" /></td></tr>');
    });
});
$(“#选择按钮”).live(“单击”),功能(){
$(“#selectedFile”).live(“更改”,函数(){
//var inp=document.getElementById('selectedFile');
files=document.getElementById('selectedFile').files;
$(“#歌曲集表格”).html(“”);
$(“#歌曲集表格”).append('Track NoSong titleartistcscreation On');
对于(变量i=0;i
HTML:


上述JavaScript代码正在运行。但是,在提交数据时,表格不会发布下面给出的数据


下一步我应该试试什么?

也许这样会更好

$(document).ready(function() {
    // submitting 
    $('#upload-form').on('submit', function() {

        // get values
    var answer = $("#album_name").val();
        // if empty
        if(answer == '') {
            alert('write album name');
        } else {
            // ajax
            $.ajax({
                url: $(this).attr('action'), // path for submit (upload.php)
                type: $(this).attr('method'), // here is post
                data: $(this).serialize(), // put all values into $_POST
                success: function(html) { 
                    // I get answer from upload.php
                    alert(html);
                }
            });
        }
        return false; // for not submitting the form
    });
});

upload.php
看起来像什么?这是因为您没有在任何地方提交表单。将ajax添加到
.live()
事件(注意:您应该使用)或添加
$(“#上传表单”).submit()
到函数末尾。您是否在
upload.php
上执行了
print\r($\u POST)
以查看发布了哪些数据?
$(document).ready(function() {
    // submitting 
    $('#upload-form').on('submit', function() {

        // get values
    var answer = $("#album_name").val();
        // if empty
        if(answer == '') {
            alert('write album name');
        } else {
            // ajax
            $.ajax({
                url: $(this).attr('action'), // path for submit (upload.php)
                type: $(this).attr('method'), // here is post
                data: $(this).serialize(), // put all values into $_POST
                success: function(html) { 
                    // I get answer from upload.php
                    alert(html);
                }
            });
        }
        return false; // for not submitting the form
    });
});