Matt
Matt

Reputation: 26971

Serializing a javascript array with Jquery

I have the following code:

<script type="text/javascript">
var checksSinceLastPostBack = new Array();

function clientSelectedIndexChanged(sender, eventArgs) {
    var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
    var serializedCheckData = checksSinceLastPostBack.serializeArray();

    if (ajaxManager != null)
        ajaxManager.ajaxRequest(serializedCheckData);
}
</script>

The

var serializedCheckData = checksSinceLastPostBack.serializeArray();

doesn't seem to work. Am I misunderstanding this?

Also if this works, how would I deserialize it in the code behind?

EDIT: Sorry, this is in ASP.NET

Upvotes: 1

Views: 581

Answers (1)

Nick Craver
Nick Craver

Reputation: 630429

.serializeArray() is for serializing form elements with name/value pairs, not a normal Array. To convert that to a string you want something like:

var serializedCheckData = checksSinceLastPostBack.join(',');

...or some other delimiter. If you have more complex data you may want to go a JSON route.

Upvotes: 2

Related Questions