首页 > 解决方案 > 我是这个 jquery 的新手,无法在下面的代码中找到语法错​​误

问题描述

我在链接按钮中的上述代码中遇到语法错误,其中 jquery 函数在 ajax 调用的成功函数中单击链接时被调用。

请协助我

    <script type="text/javascript">
function showdiv(id, sender, amt) {
        debugger;
            //   alert(id);
            //  debugger;
        $('#frmPayment')[0].src = window.appBaseUrl + '/UploadHistory/RenderTest/';
            var searchValue = $("#hdnScreenType").val();
            $('#lblTransactionQBONumber').text(id);


            $('#tbPaymentAmount').val(amt);
            if (searchValue == "2") {/*IT is bill payment screen*/
                // $("#myModal").width(1000).height(800);
                $('#frmPayment').width(400).height(500);

                //  $('#frmPayment').css('display', 'block');
                $('#divDwnLdLink').css('display', 'none');
                $('#frmPayment')[0].src = window.appBaseUrl + '/BillDetailAndPayment?id=' + searchValue + '&searchValue=' + id;
                //setTimeout(function () { $('#billpaymentdiv').css('display', 'block') }, 0);
                $('#billpaymentdiv').css('display', 'block');

            }
            else {
                $('#billpaymentdiv').css('display', 'none');
                $('#divDwnLdLink').css('display', 'block');
                var _url = "" + window.appBaseUrl + '/downloadPopup.aspx?id=' + id + '&searchValue=' + searchValue + "";
                $('#downloadLink').attr('href', _url)
            }

            return false;
        }

        function closeMe() {
            alert("Payment Added.");
            $('#frmPayment')[0].src = window.appBaseUrl + '/test.aspx';

            $('#billpaymentdiv').css('display', 'none');
            $('#divDwnLdLink').css('display', 'none');
            location.reload();
            //  $('#modalClose').click();

        }
</script>
<script>
    $('#ddBillStatus').change(function () {

                var Value = $(this).find(":selected").val()
                var selectid = { "value": Value }
                $.ajax({
                    url: "/UploadHistory/UploadHistory",
                    data: JSON.stringify(selectid),
                    type: 'POST',
                    contentType: 'application/json; charset=utf-8',
                    success: function (data) {



                        // Variable data contains the data you get from the action method
                        $('#tableprocesshistory').show();

                        var row = "";
                        row += "<thead><tr><th>Created Date</th><th>Uploaded File Name</th><th>QBO-Number</th><th>Total Amount</th><th>Vendor Name</th><th>Invoice Date</th><th>Reference Number</th><th id='paymentHeader' >Payment</th></tr></thead>";

                        $.each(data, function (index, item) {

                            row += "<tr><td>" + item.CreatedDateFormated + "</td><td>" + item.FileUniqueName + "</td><td class='nr'><span>" + item.TransactionQBONumber + "</span> </td><td>" + item.TransactionTotalAmount + "</td><td>" + item.vendorName + "</td><td>" + item.InvoiceDate + "</td><td>" + item.RefNumber + "</td><td><a href='#' onclick='String.format('javascript:return showdiv(\"{0}\",{1},\"{2}\")', " + item.TransactionQBONumber + "," + item.TransactionTotalAmount + ")'   id='myLinkButton1'  >Action</a></td></tr>";

                            // var myrow = $(this).closest("tr");    // Find the row
             //                 var abc = myrow.find(".nr").text; 
                            //$("#lblTransactionQBONumber").html(abc);

                        });
                        $("#tableprocesshistory").html(row);
                        //$(".Pager").ASPSnippets_Pager({
                        //           ActiveCssClass: "current",
                        //           PagerCssClass: "pager",
                        //           PageIndex: data.PageIndex,
                        //           PageSize: data.PageSize,
                        //           RecordCount: data.RecordCount
                        //       });
                    }
                });
                //var url = "/UploadHistory/ddBillStatus_SelectedIndexChanged/";
                //window.location.href = url;
            });

</script>

我已经编辑了我的代码并添加了 show div 功能。请看一下。帮我解决问题,因为我无法在单击操作链接时调用 show div 函数

标签: jquery

解决方案


我在操场上创建示例,请参见此处。我只是使用/echo/json/url 进行响应模拟。

$('#ddBillStatus').change(function () {
        var Value = $(this).find(":selected").val()
        var selectid = { "value": Value }
        $.ajax({
            url: "/echo/json/",
            data: { json: JSON.stringify( jsonData[selectid.value] ) },
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                // Variable data contains the data you get from the action method
                $('#tableprocesshistory').show();
                var row = "";
                row += "<thead><tr><th>Created Date</th><th>Uploaded File Name</th><th>QBO-Number</th><th>Total Amount</th><th>Vendor Name</th><th>Invoice Date</th><th>Reference Number</th><th id='paymentHeader' >Payment</th></tr></thead>";
                $.each(data, function (index, item) {
                    row += "<tr><td>" + item.CreatedDateFormated + "</td><td>" + item.FileUniqueName + "</td><td class='nr'><span>" + item.TransactionQBONumber + "</span> </td><td>" + item.TransactionTotalAmount + "</td><td>" + item.vendorName + "</td><td>" + item.InvoiceDate + "</td><td>" + item.RefNumber + "</td><td><a href='#' onclick='return showdiv(\"" + item.TransactionQBONumber + "\",\"" + item.TransactionTotalAmount + "\")' id='myLinkButton1'  >Action</a></td></tr>";
                });
                $("#tableprocesshistory").html(row);
            }
        });
    });

在操场上见:https ://jsfiddle.net/denisstukalov/rhm7j3x8/25/


推荐阅读