<i id='Pzfze'><tr id='Pzfze'><dt id='Pzfze'><q id='Pzfze'><span id='Pzfze'><b id='Pzfze'><form id='Pzfze'><ins id='Pzfze'></ins><ul id='Pzfze'></ul><sub id='Pzfze'></sub></form><legend id='Pzfze'></legend><bdo id='Pzfze'><pre id='Pzfze'><center id='Pzfze'></center></pre></bdo></b><th id='Pzfze'></th></span></q></dt></tr></i><div id='Pzfze'><tfoot id='Pzfze'></tfoot><dl id='Pzfze'><fieldset id='Pzfze'></fieldset></dl></div>
    <tfoot id='Pzfze'></tfoot>
    <legend id='Pzfze'><style id='Pzfze'><dir id='Pzfze'><q id='Pzfze'></q></dir></style></legend>
    • <bdo id='Pzfze'></bdo><ul id='Pzfze'></ul>
  1. <small id='Pzfze'></small><noframes id='Pzfze'>

    1. 如何让 Laravel 返回视图的“Content-Type"?标头为“应用程序/javascript&quo

      How to make Laravel return a View#39;s quot;Content-Typequot; header as quot;application/javascriptquot;?(如何让 Laravel 返回视图的“Content-Type?标头为“应用程序/javascript?)
      <legend id='isS4P'><style id='isS4P'><dir id='isS4P'><q id='isS4P'></q></dir></style></legend>

        <bdo id='isS4P'></bdo><ul id='isS4P'></ul>
      • <i id='isS4P'><tr id='isS4P'><dt id='isS4P'><q id='isS4P'><span id='isS4P'><b id='isS4P'><form id='isS4P'><ins id='isS4P'></ins><ul id='isS4P'></ul><sub id='isS4P'></sub></form><legend id='isS4P'></legend><bdo id='isS4P'><pre id='isS4P'><center id='isS4P'></center></pre></bdo></b><th id='isS4P'></th></span></q></dt></tr></i><div id='isS4P'><tfoot id='isS4P'></tfoot><dl id='isS4P'><fieldset id='isS4P'></fieldset></dl></div>

          <tfoot id='isS4P'></tfoot>
            <tbody id='isS4P'></tbody>

            • <small id='isS4P'></small><noframes id='isS4P'>

                本文介绍了如何让 Laravel 返回视图的“Content-Type"?标头为“应用程序/javascript"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 [script src=""] 标记从外部网站输出动态 javascript 文件以包含在内.由于视图使用 Blade 引擎,它被渲染为 text/html.

                I'm trying to output a dynamic javascript file for inclusion from external websites with the [script src=""] tag. As the view is using the Blade engine, it's rendered as text/html.

                我希望该视图的 Content-Type 标头设置为 application/javascript 只是为了避免 Chrome 用类似Resource解释为脚本,但使用 MIME 类型 text/html 传输:"

                I'd like the Content-Type header to be set to application/javascript for this view only to avoid Chrome bugging me with messages like "Resource interpreted as Script but transferred with MIME type text/html:"

                我的控制器:

                {
                    // ...
                    return View::make('embedded')->with('foo', $foo);
                }
                

                视图本身:

                <?php
                header('Content-Type: application/javascript; charset=UTF-8', true);
                ?>(function(jQuery) {
                    // append stylesheets to <head>
                    var file;
                    // ...
                })(jQuery);
                

                我发现我可以在我的视图中使用 header() 按预期添加自定义标题,例如 X-Content-Type,但是当我尝试重新定义时Content-Type 标头即使将 replace 参数设置为 true,它似乎也没有做任何事情.

                I've found that I can use header() in my view to add custom headers like X-Content-Type as expected, however when I try to redefine the Content-Type header it doesn't seem to do anything even with the replace parameter set as true.

                我肯定在这里遗漏了一些明显的东西,希望你能指出来:)

                I'm surely missing something obvious here, would appreciate your pointing it out to me :)

                非常感谢您的帮助

                推荐答案

                Laravel 允许你通过 Response 类修改头部信息,所以你必须使用它.从您的视图中删除 header 行并在您的控制器中尝试这样:

                Laravel lets you modify header information via the Response class, so you have to make use of it. Remove the header line from your view and try it like this in your controller:

                $contents = View::make('embedded')->with('foo', $foo);
                $response = Response::make($contents, $statusCode);
                $response->header('Content-Type', 'application/javascript');
                return $response;
                

                这篇关于如何让 Laravel 返回视图的“Content-Type"?标头为“应用程序/javascript"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <i id='3dRqe'><tr id='3dRqe'><dt id='3dRqe'><q id='3dRqe'><span id='3dRqe'><b id='3dRqe'><form id='3dRqe'><ins id='3dRqe'></ins><ul id='3dRqe'></ul><sub id='3dRqe'></sub></form><legend id='3dRqe'></legend><bdo id='3dRqe'><pre id='3dRqe'><center id='3dRqe'></center></pre></bdo></b><th id='3dRqe'></th></span></q></dt></tr></i><div id='3dRqe'><tfoot id='3dRqe'></tfoot><dl id='3dRqe'><fieldset id='3dRqe'></fieldset></dl></div>

                <legend id='3dRqe'><style id='3dRqe'><dir id='3dRqe'><q id='3dRqe'></q></dir></style></legend>
              1. <small id='3dRqe'></small><noframes id='3dRqe'>

                        <tbody id='3dRqe'></tbody>
                        <tfoot id='3dRqe'></tfoot>
                          <bdo id='3dRqe'></bdo><ul id='3dRqe'></ul>