为什么jQuery AJAX在第二行中不起作用? [英] why jQuery AJAX doesn't work in second row?

查看:101
本文介绍了为什么jQuery AJAX在第二行中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一张桌子上工作,我的桌子上有很多列.事实上,我只想更新在第一行中的"#btnnVerify"上具有textarea的列,但是当我单击第二行中的"#btnnVerify"无效.我已在jQuery代码中添加了警报功能,但它不适用于第二行,但可以完美地适用于第一行,我只是向您显示我的桌子,因为这些很重要.

I'm working on a table, my table has a lot of column.in fact I want to update just a column that has textarea when I click on "#btnnVerify" in first row AJAX works perfectly but when I click on "#btnnVerify" in second row it didn't work.I've added alert function in jQuery code but it didn't work on second row but it works on first row perfectly I just show to you some columns of my tables because these are important.

<table>
    <td>

        <input type='checkbox' id="StockIDCheckBox" name='result' value=@item.StockID />
<tr>    
    </td>
     <td>
         @Html.TextAreaFor(modelItem => item.Description, new { id = "description", @row = "50", @cols = "5", @class = "form-control" })

     </td>

    <td>
        <a class="btn btn-info btn-sm" data-toggle="modal" data-target="#verify" id="btnnVerify" onclick="SaveandVerify(@item.StockID)">
            <i class="glyphicon glyphicon-ok"></i>
        </a>
    </td>
    <td>
        <a class="btn btn-danger btn-sm" data-toggle="modal" data-target="#Reject" onclick="RejectGroup(@item.StockID)">
            <i class="glyphicon glyphicon-remove"></i>
        </a>
    </td>
</tr>
</table>


function SaveandVerify(id) {
        $.get("/Admin/VerifyStockBuy/SaveandVerify/" + id, function (result) {
            $("#verify #myModalLabel").html(" وضعیت درخواست این کالا در این کارگاه ");
            $("#verify #myModalBody").html(result);

        });



    }
    function RejectGroup(id) {
        $.get("/Admin/VerifyStockBuy/Reject/" + id, function (result) {
            $("#Reject #myModalLabel").html("رد درخواست");
            $("#Reject #myModalBody").html(result);

        });
    }
      $(document).ready(function () {
        $('#repAll').DataTable({
            "ordering": true,
            "language": {
                "search": "جستجو",
                "paginate": {
                    "previous": "قبلی",
                    "next": "بعدی"
                },
                "sLengthMenu": "نمایش  _MENU_  ردیف",
                "sInfo": "نمایش _START_ تا _END_ ردیف از _TOTAL_ ردیف",
                "sEmptyTable": "هیچ داده ای در دسترس نیست",
                "sInfoEmpty": "نمایش 0 ردیف  از 0 ردیف",
            },
            "columnDefs": [{ width: 1000, targets: 0 }],
        });

        $("#btnnVerify").click(function () {


            var Desc = $("#description").val();
            var stockId = $("#StockIDCheckBox").val();
            alert(Desc + ":" + stockId);
            $.ajax({

                url: '/VerifyStockBuy/EditDescription/',
                data: { id: stockId, Description: Desc },
                type: 'Post',
                dataType: "text",
                success: function (data) {
                }

            });


        });


    });


  [HttpPost]
    public ActionResult EditDescription(int id, string Description)
    {
        var desc = db.StockBuys.Find(id);
        desc.Description = Description;
        db.SaveChanges();
        return Content(Description);
    }

推荐答案

它是因为它们具有相同的ID,因此您应根据该类给出on click事件

its because they have the same ID's you should give a on click event based on the class

这篇关于为什么jQuery AJAX在第二行中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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