weixin_33743880 2015-08-21 23:04 采纳率: 0%
浏览 39

提交更改后的Ajaxform

I have an Ajax form that I need to submit as soon as the user selects an image. The problem is that the form is not submitting. Please any guidance will be appreciated

--The form ---

<form id="bgimageform" method="post" enctype="multipart/form-data" action="process.php">
    <div class="uploadFile timelineUploadBG">
        <input type="hidden" name = "bkg" value = "1"/>
        <input type="file" name="photoimg" id="bgphotoimg" class="custom-file-input">

    </div>

</form>

--- The JS Codes ---

<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.form.js"></script>
<script src="/js/jquery-ui.min.js"></script>
<script src="js/jquery.wallform.js"></script>
<script>
$(document).ready(function() {

  /* Uploading Profile BackGround Image */
  $('body').on('change','#bgphotoimg', function() {

    $("#bgimageform").ajaxForm({target:'#timelineBackground'}).submit();

  });
});
</script>
  • 写回答

2条回答 默认 最新

  • local-host 2015-08-21 23:22
    关注

    You are right, that first attempt was way off.

    Anyways, I've run some tests, and it seems if you do this, it works.

    $('body').on('change','#bgphotoimg', function() {
        alert("It should have submitted.");
    });
    

    Here is a fiddle demonstrating it. http://jsfiddle.net/gt9e160f/

    So I would have to point toward your method of submit, because the on change is definitely being called.

    I've never used jquery.form.js before, but from their docs I've pulled this:

    $(function(){
    
        //bind the form's submit to ajaxForm
        $("body").on('submit', '#bgimageform', function(e){
            $(this).ajaxForm({target:'#timelineBackground'});
            e.preventDefault();
            return false;
        });
    
        /* Uploading Profile BackGround Image */
        $('body').on('change','#bgphotoimg', function() {
            //submit the form
            $("#bgimageform").submit();
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助