JQuery提交到ColdFusion ActionPage [英] JQuery Submit To ColdFusion ActionPage

查看:207
本文介绍了JQuery提交到ColdFusion ActionPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从CFLOOP标签动态创建的HTML FORM元素。每个窗体都是唯一的,并有一个提交按钮,触发一个JQuery脚本,发布到一个actionpage。有一个隐藏的表单字段,它被分配一个唯一的记录ID,actionpage用来执行删除查询。

I have an HTML FORM element that is dynamically created from a CFLOOP tag. Each form is unique and has a submit button that fires a Jquery script that posts to an actionpage. There is a hidden form field which is assigned a unique record ID that the actionpage uses to execute the delete query.

我在浏览器的控制台窗口中收到此错误消息:
500(CFSQLTYPE CF_SQL_INTEGER的数据无效数据为528,529)

I am recieving this error message in my browser's console window: 500 (Invalid data 528,529 for CFSQLTYPE CF_SQL_INTEGER.)

这些是在运行CFLOOP时分配给我的表单隐藏输入的唯一记录ID。我的cloop目前生成2种唯一的形式和隐藏字段值:528,529。

Those are the unique record ID's that are assigned to my form's hidden input when my CFLOOP is run. My cloop is currently generating 2 unique forms and with hidden field values: "528,529" respectively.

如果我刚好在这个页面上只有一个唯一的表单,一切正常。为什么Jquery发送所有的隐藏字段的值?如何解决?

If I happen to only have one unique form on this page, everything works fine. Why is the Jquery sending over all the values of the hidden fields? How can I fix?

谢谢。
-Brian

Thanks. -Brian

FORM代码如下所示:

<cfloop query="get_trips">

                <tr class="vehicle-log-table">
                  <td class="vehicle-log-table">#DateFormat(get_trips._date, "mm-dd-yyyy")#</td>
                  <td class="vehicle-log-table"><div align="center">#get_trips.total_mileage#</div></td>
                  <td class="vehicle-log-table"><div align="center">#get_trips.expenses#</div></td>
                  <td class="vehicle-log-table"><div align="right"> 
                  <a href="actionpages/delete_trip.cfm?id=#id#">Delete Trip</a>
                  <form  enctype="multipart/form-data" class="deleteMileageForm" id="deleteMileage#get_trips.currentRow#" method="post">

                  <input type="hidden" id="hidden" name="hidden" value="#id#">
                  <input class="vehicle-log-form" type="submit" id="submit2" name="submi2" value="Delete">
                  </form>           
                 </div><br />

                <span class="errorTab2" style="display:none"> <font color="##FF0000"> <strong>Trip Not Deleted</strong></font></span>
                <span class="successTab2" style="display:none"> <font color="##00FF00"> <strong>Trip Deleted Successfully</strong></font></span>  </td>

                </td>
                </tr>

                </cfloop>

我的Javascript代码

$('#delete a[href]').click(function(e) { e.preventDefault(); });

      $('.deleteMileageForm').submit(function (e) 
      {          

        e.preventDefault();
        $.ajax({
        data: $('.deleteMileageForm').serialize(),
        type:'POST',
        url:'actionpages/delete_trip.cfm',
        success: function(){
        $('.successTab2').fadeIn(200).show();
        $('.errorTab2').fadeOut(200).hide();
            }

        });
    });

我的CF查询:

<!---Delete Trip --->                          
    <cfoutput>
    <cfquery name="deleteTrips" datasource="#datasource#">
    delete from vehicle_log
    where ID = <cfqueryparam value="#form.hidden#" cfsqltype="CF_SQL_INTEGER">
    </cfquery>
    </cfoutput>


推荐答案

不是序列化所有表单,

Instead of serializing all forms, serialize the one that was submitted.

$('#delete a[href]').click(function (e) {
    e.preventDefault();
});

$('.deleteMileageForm').submit(function (e) {
    e.preventDefault();
    var $this = $(this);
    $.ajax({
        data: $this.serialize(), // **** modified this line ****
        type: 'POST',
        url: 'actionpages/delete_trip.cfm',
        success: function () {
            var $row = $this.closest('tr');
            $('.successTab2', $row).fadeIn(200).show();
            $('.errorTab2', $row).fadeOut(200).hide();
        }
    });
});

这篇关于JQuery提交到ColdFusion ActionPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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