ajaxForm插件通常无需ajax即可提交表单 [英] ajaxForm Plugin submitting form normally without ajax

查看:102
本文介绍了ajaxForm插件通常无需ajax即可提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种情况:

首先:我在使用ajaxForm插件通过ajax上传文件的页面上有一个HTML表单,并且效果很好.

First: i have an HTML form on a page on which i'm using ajaxForm plugin to upload a file through ajax and it works fine.

第二:我正在通过php和ajax生成另一个HTML表单,我试图在其上使用相同的插件,但它会正常提交表单并在浏览器中回显结果.

Second: I am generating another HTML form through php and ajax on which i'm trying to use the same plugin but it submits the form normally and echoes out the result in the browser.

ajaxForm在动态生成的表单上不起作用吗?我知道即使问这个问题也很愚蠢,但我目前的情况似乎使我相信这一点.

Is it that ajaxForm doesn't work on dynamically generated forms?? I know that is just stupid to even ask but my current situation seems to make me believe that.

请帮助...

第一表格:这是写在HTML页面上的STATIC表格. AJAXFORM在此上可以正常工作...

First Form: This is a STATIC form written on HTML Page. AJAXFORM works fine on this...

  <form action="brand_add.php" method="post" enctype="multipart/form-data" name="brands_form" id="brands_form">
 <input type="hidden" name="brand_timeVal" id="brand_timeVal" />
 <table>
 <tr><td><label>Title<label></td></tr>
 <tr><td><input type="text" id="brand_title" name="brand_title" autocomplete="off" class="large inputTexts" placeholder="e.g. Adidas, Puma, SS, BDM, Cosco, Head, Spalding etc..." /></td></tr>
 <tr><td><label>Description<label></td></tr>
 <tr><td><textarea class="inputTexts" id="brand_desc" name="brand_desc"></textarea></td>              </tr>
<tr><td><label>Brand Image<label></td></tr>
<tr><td><input type="file" name="brand_img" id="brand_img" onchange="sub(this,this.id)">    </td></tr>
<tr><td><input type="submit" class="saveButton" value="Save" id="brand_save_btn" onclick="timing(this.id,'brand_timeVal');"><button type="button" onclick="clearBox(); return false" class="cancelButton" style="margin-left:5px;">Cancel</button></td></tr>
</table>
</form>

第二种形式:这是通过ajax请求动态生成的. AJAXFORM不起作用.

Second Form: This is dynamically generated through ajax request. AJAXFORM doesn't work.

 <?php

 $response .= "<div class='update_box_header'><span class='breadcrumb'><a href='brands.php'>Brands</a></span> / Update Brand</div>
 <div class='update_box_form'>
 <form action='#' method='post' enctype='multipart/form-data' name='brands_form_update' id='brands_form_update'>
<input type='hidden' name='brand_timeVal_update' id='brand_timeVal_update' />
<input type='hidden' name='brand_update_id' value='".$id."' />
<input type='hidden' name='brand_update_file_toggler_value' value='1' />
<table>
<tr><td><label>Title<label></td></tr>
<tr><td><input type='text' id='brand_title_update' name='brand_title_update' class='large inputTexts' value='".$row1['name']."' /></td></tr>
<tr><td><label>Description<label></td></tr>
<tr><td><textarea class='inputTexts' id='brand_desc_update' name='brand_desc_update'>".$row1['description']."</textarea></td></tr>
<tr><td><label>Brand Image<label></td></tr>

<tr><td id='brand_img_field'><img src='assets/brands/banners/".$img_path."' border='0' width='100' height='50' /></td></tr>
<tr><td><label>Upload New Image<label></td></tr>
<tr><td><input type='file' accept='image/*' name='brand_img_update' id='brand_img_update' onchange='sub(this,this.id)'></td></tr>
<tr><td><label>Status<label></td></tr>
<tr><td><select name='brand_life_update' id='brand_life_update'>";
        if($row1['status'] == 1){
$response .= "<option value='1' selected>Active</option><option value='0'>Inactive</option>";
             }
        else if($row1['status'] == 0) {
$response .= "<option value='1'>Active</option><option value='0' selected>Inactive</option>"; 
            }

  $response .= "</select></td></tr>
 <tr><td><input type='submit' class='saveButton' value='Save' id='brand_update_btn' onclick='timing(this.id,'brand_timeVal_update');'><button type='button' onclick='clearUpdateBox(); return false' class='cancelButton' style='margin-left:5px;'>Cancel</button></td></tr>
 </table>
 </form>
 </div>";


 ?> 

推荐答案

发布您的JavaScript代码.

Post your javascript code.

一个盲目的猜测是:您正在尝试将ajaxForm 实际设置在页面中.

A blind guess is : you are trying to setup your ajaxForm before it is actually present in the page.

如果要在'#brands_form_update'上运行ajaxForm,则必须请求将其插入文档中,然后然后调用ajaxForm.这应该是这样的:

If you want to run ajaxForm on '#brands_form_update', you have to request for it, insert it in the document, then call ajaxForm. This should give something like :

// $.get(...) sends the request
// $(..).append inserts the form inside the document
// $('#brands_form_update').ajaxForm() sets up the form
$.get('myDynamicForm.php', { ...data...}, function(html){
    $('*mySelector*').append(html);
    $('#brands_form_update').ajaxForm();
});

这篇关于ajaxForm插件通常无需ajax即可提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆