簡體   English   中英

如何在Codeigniter中設置Img文件的Ajax上傳

[英]How to set Ajax Upload of Img File in Codeigniter

我閱讀了許多有關使用codeigniter上載文件的教程,但問題是這些教程在我的情況下無法正常工作,並且我無法通過ajax上載成功,請求失敗,並且頁面在非ajax的導航欄中加載,我想要找到一個非常詳細的教程來解釋codeigniter中ajax上傳的基礎。 或有關該主題的一些建議。

該代碼對我來說很好,您只需要在控制器上對其進行管理即可。

不要忘記添加jquery.form.min.js。

<script>
function service_switch()
{
    $('#service_update').ajaxSubmit({ 

        beforeSubmit: function() {
            $("#switch").html('<img alt=""'+
            ' src="<?=base_url()."assets/default/"?>img/preloaders/ajax-loader.gif"  align="center" />  0% Switching.');
        },

        uploadProgress: function (event, position, total, percentComplete){ 
            $("#switch").html('<img alt=""'+
            ' src="<?=base_url()."assets/default/"?>img/preloaders/ajax-loader.gif"  align="center" />  '+perc+'% Switching ...');
            },

        success:function (d){
            if(d=='success'){
                $("#switch").html(' 100% Switched Successfully !');
            }else{
                $("#switch").html(' '+d);
            }
        },

        error:function(){$("#switch").html('segmentation fault');},

        resetForm: true 
    }); 

}
</script>


<!--Firmware MAC Configuaration Form-->
<?php

//shell_exec("gnome-terminal -e ping 127.0.0.1 &"); 
//shell_exec("geany"); 

$attribute = array('class'=> 'box validate','id'=>'service_update');?>

<?php echo form_open('firmware_update/service_switch',$attribute);?>
<div class="header">
    <h2>
        Service Update
    </h2>
</div>
<div class="content">
    <div class="row">
        <label>
            <strong>Switch Service </strong>
        </label>
        <div>
            <div>
                <input type="radio" name="demo" id="demo1"  value="1">
                <label for="demo1">demo1</label>
            </div>
            <div>
                <input type="radio" name="demo" id="demo2"  value="2">
                <label for="f4_rb_dis2">service2_RX</label>
            </div>
            <div>
                <input type="radio" name="demo" id="demo3"  value="3">
                <label for="demo1">service2_TX</label>
            </div>
            <div>
                <input type="radio" name="demo" id="demo4"  value="4">
                <label for="demo1">service3</label>
            </div>
        </div>
    </div>
</div>
<div class="actions">
    <div class="right">
        <a onclick="service_switch();" class="button blue flat" >Switch Service</a>
    </div>
</div>
<?php echo form_close(); ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM