0

I'm very new to ajax/javascript so I will try my best to explain my problem. Here's what I have so far:

$(function () {

        $("#chkFilter").on("click", "input", function (e) 
        {
            var filterCheckboxes = new Array();
            $("#chkFilter").find("input:checked").each(function () {
                //console.log($(this).val()); //works fine
                filterCheckboxes.push($(this).val());
                console.log($(this).val());

                //var filterCheckboxes = new Array();
                //for (var i = 0; i < e.length; i++) {
                //    if (e[i].checked)
                //        filterCheckboxes.push(e[i].value);
                //}
            });
        console.log("calling ajax");
        $.ajax({
            url: "/tools/oppy/Default.aspx",
            type: "post",
            dataType: "json",
            data: { UpdateQuery: filterCheckboxes }, // using the parameter name
            success: function (result) {
                if (result.success) {
                }
                else {
                }
            }
        });
        });
    });

Every time a checkbox is checked, ajax passes the data onto the server. Here is an example of some checkbox values after a few have been checked in the data form obtained from the Developer's Console:

1 Answer 1

1

You can try the following code:

filterCheckboxes.push($(this).prop("name") + "=" + $(this).val());
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Do you have any recommendations on how to parse it on the server? I assume, given my code, will send it to the server as a URL string?
Well, i would use the substring method on the server to split the Request["UpdateQuery"] value.
Request["UpdateQuery"] - UpdateQuery is a method. From my understanding, UpdateQuery: filterCheckboxes means I'm passing the array to a method on the server. Would I still do Request[UpdateQuery] on page load?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.