如何在jquery中单击按钮时使用serializeArray [英] how to use serializeArray on button click in jquery

查看:61
本文介绍了如何在jquery中单击按钮时使用serializeArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i希望在按钮点击的jquery中将数据添加到数组中



code :

Hi guys,

i want to add data into arrays in jquery on button click

code:

<script type="text/javascript">
        function ADD2Grid() {
            //Getting the source data with ajax GET request
            var tt = $('#ddltitle :selected').text() + "|" +
                $("#<%=txtfn.ClientID %>").val() + "|" +
                $("#<%=txtmn.ClientID %>").val() + "|" +
                $("#<%=txtln.ClientID %>").val();
            //alert(tt);
            var data = [{ "empName": $("#<%=txtfn.ClientID %>").val(),
                "age": $("#<%=txtmn.ClientID %>").val(),
                "department": { "id": "1234", "name": "Sales" },
                "author": $("#<%=txtln.ClientID %>").val()
            }];

            // prepare the data
            var source =
{
    datatype: "json",
    datafields: [
        { name: 'empName' },
        { name: 'age' },
        { name: 'id', map: 'department>id' },
        { name: 'name', map: 'department>name' },
        { name: 'author' }
    ],
    localdata: data
};
            var dataAdapter = new $.jqx.dataAdapter(source,
                {  contentType: 'application/json; charset=utf-8'}
            );
            $("#jqxgrid").jqxGrid({
                source: dataAdapter,
                theme: 'classic',
                columns: [
                    { text: 'empName', dataField: 'empName', width: 50 },
                    { text: 'age', dataField: 'age', width: 250 },
                    { text: 'name', dataField: 'name', width: 250 },
                    { text: 'author', dataField: 'author', width: 250 }
                ]
            });
        };
    </script>







i已经尝试过这段代码,但它并没有激动人心。




i have tried this code, but its not excuting.

var sp = tt.split("|");
            if (getData == null) {
                getData = "{'empName' :'" + sp[0] + "','age':'" + sp[1] + "','department':'" + "Sales" + "','author':'" + sp[2] + "'},";
            }
            else {
                getData += "{'empName' :'" + sp[0] + "','age':'" + sp[1] + "','department':'" + "Sales" + "','author':'" + sp[2] + "'},";
            }
            
            var fullData = "[" + getData.replace(/'/g, '"') + "]";
            alert(fullData); // Excutes
            var data = JSON.parse(fullData);
            alert(data); // not Excuting





错误



Error

Uncaught SyntaxError: Unexpected token ]



任何人都可以帮助我。





谢谢


Can anyone please help me.


Thanks

推荐答案

('#ddltitle:selected')。text()+| +
('#ddltitle :selected').text() + "|" +


(#<%= txtfn.ClientID%>)。val()+|+
("#<%=txtfn.ClientID %>").val() + "|" +


(# <%= txtmn.ClientID%>)。val()+|+
("#<%=txtmn.ClientID %>").val() + "|" +


这篇关于如何在jquery中单击按钮时使用serializeArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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