解析AJAX表单提交

时间:2014-03-21 21:46:22

标签: ajax jquery-mobile coldfusion-9

我有一个jQuery Mobile应用程序,它有几个动态表单。我要做的是解析表单提交并获取表单字段的值。从处理脚本收到数据时,它看起来如下。

str:app_EAD17776-155D-D714-FB34E569AA814746_ser=a&app_EAD17776-155D-D714-FB34E569AA814746_app=A1234Washer%2C+ABC&app_EAD17776-155D-D714-FB34E569AA814746_chk=&app_EAD17776-155D-D714-FB34E569AA814747_ser=a&app_EAD17776-155D-D714-FB34E569AA814747_app=A1234Dryer%2C+ABC&app_EAD17776-155D-D714-FB34E569AA814747_chk=

我需要做的就是获取每个值的值,将它们放在一个二维数组中。

我需要进一步解释表格,以便你看起来像我的问题。我将打破形式。

  • 此表单字段是设备序列号: app_EAD17776-155D-D714-FB34E569AA814746_ser =α
  • applianceType为:EAD17776-155D-D714-FB34E569AA814746
  • EAD17776-155D-D714-FB34E569AA814746 =垫圈
  • 序列号= a

  • 此表单字段是设备的品牌和名称: app_EAD17776-155D-D714-FB34E569AA814746_app = A1234Washer%2C + ABC
  • 设备类型为:EAD17776-155D-D714-FB34E569AA814746
  • 洗衣机品牌和名称:A1234Washer,ABC

  • 此表单字段是一个有效的复选框: app_EAD17776-155D-D714-FB34E569AA814746_chk =
  • applianceType为:EAD17776-155D-D714-FB34E569AA814746

因此,我尝试对此信息进行的操作是循环此数据并插入表单值以及相应的applianceType。首先,我查询活动设备类型。

<cfquery name="qApplianceTypes">
    SELECT *
    FROM ApplianceTypes
    WHERE Active = <cfqueryparam value="1" cfsqltype="cf_sql_bit">
</cfquery>

然后我遍历结果并匹配formfields applianceTypes以获取值并将其应用于数组。

    <cfset applianceTypeArray = ArrayNew(2)>

    <cfset count = 1>

<cfloop query="qqApplianceTypes">
    <!--- [1] appliance id ---->
    <cfset applianceTypeArray[count][1]     =   qApplianceType.ApplianceTypeID>
        <!--- loop over formfields to find relative id --->
        <cfloop index="i" list="#Form.str#" delimiters=",">
            <cfif right(i, 4) IS "_IDd" and qApplianceType.ApplianceTypeID is "#GetToken(ListFirst(i,' '),2,'_')#" >
                <!--- [4] appliance ---->
                <cfset applianceTypeArray[count][2]     =   #FORM[i]#>
            </cfif>
        </cfloop>
        <!--- loop over formfields to find relative serialnumbers --->
        <cfloop index="i" list="#Form.str#" delimiters=",">
            <cfif right(i, 4) IS "_ser" and qApplianceType.ApplianceTypeID is "#GetToken(ListFirst(i,' '),2,'_')#" >
                <!--- [3] serial number ---->
                <cfset applianceTypeArray[count][3]     =   #FORM[i]#>
            </cfif>
        </cfloop>
        <!--- loop over formfields to find relative appliance --->
        <cfloop index="i" list="#Form.str#" delimiters=",">
            <cfif right(i, 4) IS "_app" and qApplianceType.ApplianceTypeID is "#GetToken(ListFirst(i,' '),2,'_')#" >
                <!--- [4] appliance ---->
                <cfset applianceTypeArray[count][4]     =   #FORM[i]#>
            </cfif>
        </cfloop>
    <cfset applianceTypeArray[count][5]     =   qApplianceType.ApplianceTypeID>

        <!--- loop over formfields to find relative active or innactive --->
        <cfloop index="i" list="#Form.str#" delimiters=",">
            <cfif right(i, 4) IS "_chk" and qApplianceType.ApplianceTypeID is "#GetToken(ListFirst(i,' '),2,'_')#" >
                <!--- [2] active ---->
                <cfset applianceTypeArray[count][6]     =   #FORM[i]#>
            </cfif>
        </cfloop>
    <cfset qloopcount2 = #count#>
    <cfset count = count+1>
</cfloop>

一旦我填充了applianceTypeArray,我只需循环遍历数组以填充数据库。

问题在于我没有得到这些值。它的作品是一个表格帖子,但我必须使用get。当我转储数组时,我得到以下数据。

0: "EAD17776-155D-D714-FB34E569AA814746"
1: null
2: null
3: null
4: "EAD17776-155D-D714-FB34E569AA814746"

0: "EAD17776-155D-D714-FB34E569AA814747"
1: null
2: null
3: null
4: "EAD17776-155D-D714-FB34E569AA814747"

第一个问题是元素以0而不是1开头,而我没有得到元素6.其次是元素0 - 4不是值,而是设备类型ID。 有什么建议吗?

0 个答案:

没有答案