dongmi1941 2014-09-25 12:58
浏览 39

一个页面上有两个AJAX表单,一个清除另一个表单

I have two forms usin ajax on one page, one for uploading an image and the other sending information via mail.

When I submit one it clears the content of the other one.

My html:

<form class="inputform">
    <input required size="60" maxlength="80" class="form-control" name="Location[zendernaam]" id="Location_zendernaam" type="text">
    <!--more input fields-->

    <input type="submit" class="submit" style="display:none;">
</form>

<form id="form" class="imageuploadform" action="<?php echo get_home_url(); ?>/wp-content/themes/PandoraBox/ajaxupload.php" method="post" enctype="multipart/form-data">
    <input id="uploadImage" type="file" accept="image/*" name="image" />
    <input id="button" class="image-upload" type="submit" value="Upload">
</form>
<div id="preview" style="display:none"></div>

<input id="submitform" type="button" value="Verzend">

My javascript/jquery:

<script type="text/javascript">
$("#submitform").click(function(){
    $('.inputform .submit').click();
    return false;
});
$(".inputform").submit(function( event ){
    event.preventDefault();

    post_data = {
        'titel'             : $("#Location_title").val(), 
        'hoofdcategorie'    : $("#Location_hoofd1").val(), 
        //more fields
    };

    $.ajax({
        type: "POST",
        url: "<?php echo get_home_url(); ?>/wp-content/themes/PandoraBox/verzend-inzending.php",
        data: post_data,
        success: function(){
            alert('top!');
        }
    });

});

</script>

First the user fills in the fields, after that he can upload an image and preview it. When you click submit on the image upload form it clears all the values of the first form.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?