在firefox和edge浏览器上查看时,如何在datatable上显示ajax响应 [英] How do I display ajax response on datatable while viewing on firefox and edge browsers

查看:383
本文介绍了在firefox和edge浏览器上查看时,如何在datatable上显示ajax响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的报告显示在Google Chrome上显示正常,但在尝试在Firefox或Edge浏览器上查看时,json响应显示在浏览器上而不是数据表上。 firefox上的示例回复如下:

I have i report that displays fine on Google chrome, but while trying to view on Firefox or Edge browser, the json response displays on the browser instead of the datatable. Sample response on firefox below:

"[{\"RegisteredBy\":\"Admin\",\"PatientRegNo\":\"De723\",\"PaymentType\":\"Cash\"}]"





我有尝试将以下代码分别包含在ajax函数和json结果操作中:



I have tried including the below code to the ajax function and json result action respectively:

contentType: 'application/json, charset=utf-8',




return Json(data,JsonRequestBehavior.AllowGet);





我尝试过:



我的Ajax功能:



What I have tried:

My Ajax Function:

var str = $("#frmReport").serialize();
        $("#searchBtn").prop("disabled", true);
        $.ajax({
            url: url,
            type: "POST",
            data: str,
            cache: false,
            dataType: "json",              
            success: function (_data) {
                var arr = $.map(JSON.parse(_data), function (el) { return el });                   
                table.clear();
                table.destroy();
                $('#tblReport').dataTable({
                    data: arr,
                    columns: [
                        { "data": "RegisteredBy"},
                        { "data": "PatientRegNo"},
                        { "data": "PaymentType"},                           
                    ],
                    dom: 'Bfrtip',
                    buttons: [
                        'copy', 'csv', 'excel',
                        {
                            extend: 'pdfHtml5',
                            orientation: 'portrait',
                            pageSize: 'A4'
                        }

                    ]
                });

            }
        });
        table = $("#tblReport").DataTable();
    });
});





我的JsonResult行动方法代码:



My JsonResult Action Method Code:

getEntries = superAdminForBillingRepository.GetByRegNoOnly(regNo);
var data = Newtonsoft.Json.JsonConvert.SerializeObject(getEntries);
return Json(data);





我想要无论使用何种浏览器,都可以查看有关数据表的报告。



I want to be able to view the report on datatable irrespective of the browser used.

推荐答案

#frmReport)。serialize();
("#frmReport").serialize();


#searchBtn)。prop( disabled true );
("#searchBtn").prop("disabled", true);


.ajax({
url:url,
type: POST
data:str,
cache: false
dataType: json
成功: function (_ data){
var arr =
.ajax({ url: url, type: "POST", data: str, cache: false, dataType: "json", success: function (_data) { var arr =


这篇关于在firefox和edge浏览器上查看时,如何在datatable上显示ajax响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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