doumubi6784 2019-05-02 05:59
浏览 54

通过具有不同id的更改事件中的ajax发送图像

iam trying to update image through on change event in codeigniter and want to update with different id each time when i select the image different. please help with the solution thanks in advance Each time the product_image_id should change according to db table

$(document).ready(function(){

    $('.images').on('change',function(){
        var link = '<?php echo site_url('menu_management_con/editimage');?>';   
        var product_image_id = $('.id').val();
    var formData= new FormData();
    var file = this.files[0];
    formData.append('file', file);
    formData.append('product_image_id',product_image_id);
        $.ajax({
            type:'POST',
            url: link,
            data : formData,
            cache: false,
            processData:false,
            contentType:false,
            success:function(data){
                alert(data);
            }
        });

    });
    });

this is my html code

am trying to update image through on change event in codeigniter

<form id="add_produc" method="post" class="addProduct" name="add_produc" action="<?=base_url()."menu/product_edit/".$data['product_id'].'/'.$data['category_id'] ?>" enctype="multipart/form-data" >

                    <div class="row">
                        <div class="col-sm-12">
                            <table class="table table-bordered">
                                <tr>
                                    <th class="head" colspan="2">Edit</th>
                                </tr>

                                    <tr>
                                        <td><label for="Name">Name:</label></td>
                                        <td>
                                            <input type="text" name="product_name" value="<?= $data['product_name']?>" id="product_name" class="form-control" placeholder="Name">
                                        </td>
                                    </tr>

                                    <tr>
                                        <td> <label for="Description">Description:</label> </td>
                                        <td>
                                            <input type="text" name="product_description" value="<?= $data['product_description']?>" id="product_description" class="form-control" placeholder="description">
                                        </td>
                                    </tr>

                                    <tr >
                                        <td><label for="Photo">Photo:</label> </td>
                                        <td>
                                            <div id="addField0">
                                                <input type="file" name="product_photo[]" multiple  id="product_photo" class="form-control" accept="image/*"><br>
                                            </div>
                                            <button id="add-more-edit" name="add-more-edit" class="btn btn-primary">Add More</button>
                                        </td>
                                    </tr>
                                    <?php
                                        if(!empty($image)){
                                            foreach ($image as $result){
                                    ?>
                                    <tr class='imagelocation<?= $result->product_image_id ?>'>
                                        <td colspan="2" align='center'>
                                            <input type="text" name="product_image_id" value="<?= $result->product_image_id?>" id="product_photo" class="form-control id" >
                                            <input type="file" name="image" id="image" class="form-control images" accept="image/*">

                                            <img class='img-rounded' height="50" width="50" src="<?= base_url('/assets/uploads/products/'.$result->product_photo)?>" style="vertical-align: middle;">
                                            <span style="cursor:pointer;" onclick="javascript:deleteimage(<?php echo $result->product_image_id ?>)">X</span>
                                        </td>
                                    </tr>
                                    <?php
                                            }
                                        }else{
                                            echo '<div class="empty">No Products Found...!</div>';
                                        }
                                    ?>
                                    <tr>
                                        <td colspan="2">
                                            <input type="hidden" name="sub_category_id" value="<?= $data['sub_category_id']?>" id="sub_category_name" class="form-control">
                                            <input type="submit" name="update_product" id="update_product" class="btn btn-info btn-small" value="Update">
                                        </td>
                                    </tr>

                            </table>
                        </div>
                    </div>
                </form>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000