donglaoping9702 2013-12-12 07:51
浏览 34
已采纳

ajaxForm插件通常没有ajax提交表单

I have two scenarios:

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.

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.

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.

Please help...

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>

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>";


 ?> 
  • 写回答

1条回答 默认 最新

  • douxue7196 2013-12-12 08:10
    关注

    Post your javascript code.


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

    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();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)