为什么我的JavaScript页面无法加载数据表?

时间:2019-05-20 11:00:28

标签: javascript c# jquery ajax asp.net-mvc

我不知道我的问题是C#还是JavaScript,但是我认为我的问题从ajax开始,我试图将类型从GET更改为POST

这是我的JavaScript代码:

//Load Data in Table when documents is ready
var currentPassport = '';
var counter = 0;
var empPass = [];
var resultGlobal = [];

function loadData() {
    //INITIALIZ Controls//

    //i-check
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });

    //start loading snapit
    $('#ibox1').children('.ibox-content').toggleClass('sk-loading');

    //populate data table
    $.ajax({
        url: "/VisaApprovment/PassportAll",
        type: "GET",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (result) {            
            empPass = JSON.parse(result);            
            var html = '';
            $.each(empPass, function (key, item) {
                html += '<tr>';
                html += '<td style="vertical-align: middle;">' + item.userNationalID + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.fullNameA !== undefined ? item.fullNameA : "-") + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.fullNameE !== undefined ? item.fullNameE : "-") + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.nationality !== undefined ? item.nationality : "-") + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.userMobile !== undefined ? item.userMobile : "-") + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.PassportNo !== undefined ? item.PassportNo : "-") + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.PassportIssueDate !== undefined ? moment(item.PassportIssueDate).format("YYYY/MM/DD") : "-") + '</td>';
                html += '<td style="vertical-align: middle;">' + (item.PassportExpireDate !== undefined ? moment(item.PassportExpireDate).format("YYYY/MM/DD") : "-") + '</td>';
                html += '<td style="vertical-align: middle;">';
                html += '<td style="vertical-align: middle;">' + (item.attachmentID !== undefined ? '<a onclick="downloadDoc(' + item.attachmentID + ')">' + item.attachmentID + '</a>' : "لا يوجد جواز") + '</td>';
                html += '</td > </tr >';
            });            
            $("#myTable").find('tbody').remove();
            $("#myTable").find('tfoot').remove();

            $('#myTable').append('<tbody class="tbody">' + html + '</tbody><tfoot><tr class="footable-paging"><td colspan="9"><div class="footable-pagination-wrapper"><ul class="pagination pull-right"><li id="arrowFirst" class="footable-page-arrow disabled"><a data-page="first" href="#first">«</a></li><li class="footable-page-arrow disabled"><a data-page="prev" href="#prev">‹</a></li><li class="footable-page active"><a data-page="0" href="#">1</a></li><li class="footable-page"><a data-page="1" href="#">2</a></li><li class="footable-page-arrow"><a data-page="next" href="#next">›</a></li><li id="arrowLast" class="footable-page-arrow"><a data-page="last" href="#last">»</a></li></ul></div></td></tr></tfoot>');
            $('#myTable').footable({
                "paging": {
                    "enabled": true,
                    "data-page-size": "15",
                    "data-limit-navigation": "3"
                },
                "sorting": {
                    "enabled": true
                }
            });
            $(".sparkline").sparkline([13, 10], {
                type: 'pie',
                height: '25',
                sliceColors: ['#1ab394', '#F5F5F5']
            });
            clientRefresh();
            $('#ibox1').children('.ibox-content').toggleClass('sk-loading'); $('#ibox1').addClass('bounce');
            $("#search").val("");

        },
        error: function (errormessage) {
            console.log(errormessage.responseText);
            //window.location.href = '/Home';
        }

    });


}

这是我的C#代码:

 [Route("VisaApprovment/PassportAll")]
        [HttpPost]
        public async Task<JsonResult> PassportAll(AllPassport AllPassport)
        {

            List<FileDetail> ffd = new List<FileDetail>();
            Result result = new Result();
            SqlConnection con = new SqlConnection(cs);
            SqlDataReader reader;



            if (Session["ListOfAttachment"] as List<FileDetail> != null)
                ffd.AddRange(Session["ListOfAttachment"] as List<FileDetail>);

          AllPassport.attachmentID = ffd.Where(o => o.Id == AllPassport.PassportNo).First().FileContent;



            using (con)
            {
                try
                {
                    con.Open();

                    //read annual balance
                    SqlCommand com = new SqlCommand("getEmpPassportsReport", con);
                    com.CommandType = CommandType.StoredProcedure;

                    com.Parameters.AddWithValue("@userNationalID", AllPassport.userNationalID);
                    com.Parameters.AddWithValue("@fullNameA", AllPassport.fullNameA);
                    com.Parameters.AddWithValue("@fullNameE", AllPassport.fullNameE);
                    com.Parameters.AddWithValue("@nationality", AllPassport.nationality);
                    com.Parameters.AddWithValue("@userMobile", AllPassport.userMobile);
                    com.Parameters.AddWithValue("@PassportNo", AllPassport.PassportNo);
                    com.Parameters.AddWithValue("@PassportIssueDate", AllPassport.PassportIssueDate);
                    com.Parameters.AddWithValue("@PassportExpireDate", AllPassport.PassportExpireDate);
                    com.Parameters.AddWithValue("@attachmentID", AllPassport.attachmentID);
                    reader = await com.ExecuteReaderAsync();
                    reader.Read();
                    result.Code = Convert.ToInt16(reader["result_"].ToString());
                    result.Title = reader["result_"].ToString();
                    result.Data = reader["message_"].ToString();
                    if (result.Code == 1)
                    {
                        result.Title = "تمت العملية بنجاح ";
                    }
                    else
                    {
                        result.Title = "خطأ";
                    }
                }
                catch (Exception err)
                {
                    result.Code = 500;
                    result.Title = "Internal Server Erorr";
                    result.Data = err.Message;

                    Catcher.doCatcher("HR", "PassportAll", err.ToString(), ((Employee)Session["emp"]).userID_FK.ToString());

                }

                con.Close();
            }


            Session["ListOfAttachment"] = null;
            return Json(result, JsonRequestBehavior.AllowGet);
        }

0 个答案:

没有答案