将多个值(文件)从javascript发送到php

将多个值(文件)从javascript发送到php,javascript,php,Javascript,Php,我有这个密码 var action = $("#action").val(); var z_product_id = $("#z_product_id").val(); var product_id = $("#product_id").val(); $.post('ajaxGetOperations.php', {action: action, z_product_id: z_product_id, product_id: product_id}, function(dat

我有这个密码

var action = $("#action").val();
var z_product_id = $("#z_product_id").val(); 
var product_id = $("#product_id").val(); 
$.post('ajaxGetOperations.php',
    {action: action, z_product_id: z_product_id, product_id: product_id},
    function(data)
    {
        $('#respons').html(data);
        $('#hand_product_id').val(product_id);
    }) ;                                         
}

我可以发送action和Z_产品并。。。在这一行中转到php页面

{action: action, z_product_id: z_product_id, product_id: product_id}
但我不知道如何将文件值发送到php页面。 这是五月的html代码

<table class="table table-striped table-hover">  
    <tr>
        <td><input type='text' size="4" value='$z_product[id]' id='z_product_id' /></td>
        <td>$z_product[name]</td>                          
        <td><input type='text' size="4" value='$product[id]' id='product_id' /></td>
        <td>$product[name]</td>                                                              
    </tr> 
    <tr>      
        <td colspan='4'>
            <div class="col-lg-6 col-sm-6 col-md-6 -col-xs-12">
                <label class="" for="filebutton">ارسال عکس</label>
                <input id="image" name="image" class="input-file" type="file">
            </div>
        </td>                                                               
    </tr>                                                               
    </tr>         
    <tr>      
        <td></td>
        <td></td>     
        <td></td>     
        <td>
            <button onclick='setDBInfo(this.value)' value='1' id='action'>ارسال </button>
            <button onclick='setDBInfo(this.value)' value='0' id='action'>رد </button>
        </td>                                                               
    </tr>
</table> 
实际上,我无法访问php中的文件值。 我想访问php中的多个文件值,带javascript.post吗?
如何实现这一点?

最简单的方法是将表包装成表单并发送到php页面。但是如果您不想这样做,那么您需要编写js代码从HTML元素获取文件值。

试试这个

<form name="my_form">
<table class="table table-striped table-hover">  
    <tr>
        <td><input type='text' size="4" name="z_product_id" value='$z_product[id]' id='z_product_id' /></td>
        <td>$z_product[name]</td>                          
        <td><input type='text' size="4" name="product_id" value='$product[id]' id='product_id' /></td>
        <td>$product[name]</td>                                                              
    </tr> 
    <tr>      
        <td colspan='4'>
            <div class="col-lg-6 col-sm-6 col-md-6 -col-xs-12">
                <label class="" for="filebutton">ارسال عکس</label>
                <input id="image" name="image" class="input-file" type="file">
            </div>
        </td>                                                               
    </tr>                                                               
    </tr>         
    <tr>      
        <td></td>
        <td></td>     
        <td></td>     
        <td>
            <button type="submit" value='1' id='action'>ارسال </button>
            <button onclick='setDBInfo(this.value)' value='0' id='action'>رد </button>
        </td>                                                               
    </tr>
</table> 
</form>
在php中,像往常一样检索值

$p_id = $_POST['z_product_id'];
$p_id = $_FILES['image'];

简言之,使用formData对象将真正帮助您…

我需要编写js代码从HTML元素中获取文件,例如:var file=$file.val;
$p_id = $_POST['z_product_id'];
$p_id = $_FILES['image'];