JSReport error: Failed to load resource: the server responded with a status of 404 ()

JSReport error: Failed to load resource: the server responded with a status of 404 ()

我是第一次做JS报表。我在 JS 报告工作室中创建了我的 JS 报告模板。现在,我正尝试从客户端的 asp.net 应用程序中调用它。但是当我渲染它时,我的客户端出现错误 "Cannot POST /studio/templates/xyz/api/report" 。我已经在浏览器控制台中检查过了,它显示 "The server responded with a status of 404 ()"。

这是我的客户端代码,

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="jsReportTesting.aspx.vb" Inherits="TraceMate.jsReportTesting" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h1>JS Report Testing</h1>
            
            <input type="button" title="test" onclick="generateReport();" value="Get PDF Report" />
            <div id="placeholder" style="height: 900px;"></div>

        </div>
    </form>

    <script src="script/jsreport/jsreport.js"></script>
    <script type="text/javascript">
        jsreport.headers['Authorization'] = "Basic " + btoa("myusername:mypasword")
        jsreport.serverUrl = 'https://reports.myapp.de/studio/templates/xYZas';
        //URL path in which jsreport server runs    
        /* For the sample purpose, the below JSON can be used. But in real time this data should come from Web API calls */

        var json_data = {
            "employees": [{
                "name": "A",
                "team": "X"
            },
            {
                "name": "B",
                "team": "Y"
            },
            {
                "name": "C",
                "team": "Z"
            }
            ]
        }

        function generateReport() {
            var request = {
                template: {
                    "name": "samplereport",
                    "recipe": "phantom-pdf",
                    "engine": "handlebars",
                    "chrome": {
                        "landscape": true
                    }
                },
                data: json_data,
                "options": { "reports": { "save": true } }
            };
            jsreport.render(document.getElementById("placeholder"), request);
            // here ”placeholder” is div tag name in html page    
        }
    </script>
</body>
</html>

有人可以告诉我我的代码哪里做错了吗?提前致谢!

  • serverUrl 应该是这样的
jsreport.serverUrl = 'https://reports.myapp.de';
  • jsreport.render 不适用于授权,如果您的 jsreport 服务器已通过身份验证,则需要使用 renderAsync。查看文档 https://jsreport.net/learn/browser-client

  • 你最近好像在用phantom-pdf recipe that is old. It is recommended to use chrome-pdf

  • 如果您的应用程序是 public,您可能不想在 <script> 标记中公开 jsreport 服务器凭据。在这种情况下,最好从服务器端调用 jsreport。