<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

      时间:2023-10-31
      <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"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Laravel 4:验证前修剪输入的最佳实践 下一篇:在 laravel 项目中生成动态站点地图而不使用作曲家

                相关文章

                <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'>

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