javascript - Checkbox ajax request on checkuncheck - Stack Overflow

I have a checkbox on razor view engine as:@Html.CheckBoxFor(model => model.Attempt, new { id = "

I have a checkbox on razor view engine as:

@Html.CheckBoxFor(model => model.Attempt, new { id = "Attempt" })

I wanted to make ajax request on each check/uncheck on the checkbox. So, i used the javascript,

$(document).ready(function () {

// Some other functions here

        $('#Attempt input:checkbox').change(function () {
            $.ajax({
                url: '@Url.Action("Select", "Test")',
                type: 'POST',
                data: { attempt: true }

            });

        })


    });

But it is not working at all. No request is being sent at all. What am i missing? Also, how to map data attempt true or false according to check/uncheck ?

I have a checkbox on razor view engine as:

@Html.CheckBoxFor(model => model.Attempt, new { id = "Attempt" })

I wanted to make ajax request on each check/uncheck on the checkbox. So, i used the javascript,

$(document).ready(function () {

// Some other functions here

        $('#Attempt input:checkbox').change(function () {
            $.ajax({
                url: '@Url.Action("Select", "Test")',
                type: 'POST',
                data: { attempt: true }

            });

        })


    });

But it is not working at all. No request is being sent at all. What am i missing? Also, how to map data attempt true or false according to check/uncheck ?

Share Improve this question edited Jul 25, 2012 at 13:07 nebula asked Jul 25, 2012 at 12:59 nebulanebula 4,00213 gold badges55 silver badges83 bronze badges 2
  • data: { attempt: true } delete , – Ron van der Heijden Commented Jul 25, 2012 at 13:06
  • um ! actually there was success function just below i deleted success function and , was what remained there. That was not the error though. – nebula Commented Jul 25, 2012 at 13:08
Add a ment  | 

2 Answers 2

Reset to default 4

I don't know why it didn't work but i modified slightly to make it work.

$('#Attempt').change(function () {
            if ($('#Attempt').is(':checked')) {
                $.ajax({
                    url: '@Url.Action("Select","Test")',
                    data: { isLocked: true },

                    type: 'POST',
                    dataType: "json"
                });
            }
});

You selector says find an element that has an id Attempt and than find the checkboxes inside. I believe you selector should just be the id unless I do not understand the the plating language you are using.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745314602a4622156.html

相关推荐

  • javascript - Checkbox ajax request on checkuncheck - Stack Overflow

    I have a checkbox on razor view engine as:@Html.CheckBoxFor(model => model.Attempt, new { id = "

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信