CakePHP - 网页尝试加载webroot中的所有js文件

时间:2016-09-09 16:14:44

标签: javascript cakephp

我有一个使用CakePHP的大项目。我有一个网页,我只希望它在<script type="text/x-jsrender" id="postsTemplate"> ... <div class="feed-post-options"> <div class="feed-post-buttons" data-postId="{{:PostId}}"> <p class="post-feed-options" id = "postLikesCount">{{:PostLikesCount}}</p> {{if PostIsLiked }} <a class="small-icons-feed" href="javascript:likePost('{{:PostId}}')"><span class="glyphicon glyphicon-thumbs-up like"></span></a> {{else}} <div> <a class="small-icons-feed" href="javascript:likePost('{{:PostId}}')"><span class="glyphicon glyphicon-thumbs-up-checked like"></span></a> </div> {{/if}} <p class="post-feed-options">{{:NumberOfComments}}</p> <a class="small-icons-feed" href="#"><span class="glyphicon glyphicon-comment comment" title="Comment"></span></a> <p class="post-feed-options">0</p> <input id="postIdValue" type="hidden" value={{:PostId}} /> <a class="small-icons-feed" href="javascript:shareModal('{{:PostId}}')" name="Save" data-toggle="modal" data-target="#shareModal" onclick="shareModal('{{:PostId}}')"><span class="glyphicon glyphicon-share share" title="Share"></span> </a> </div> ... </div> .... </script> <script type="text/javascript"> function likePost(postId) { var appUserId = $("#appUserValue").val(); var request = $.ajax("/Home/LikeComment", { type: "GET", dataType: "html", data: { appUserId: $("#appUserValue").val(), postId: postId }, success: function (data) { //how can i replace the number of the likes without refresh }}); request.done(function(jqXHR, textStatus){//just debug alert("Request done: " + textStatus) }); request.fail(function(jqXHR, textStatus) { alert( "Request failed: " + textStatus ); }); } </script>的子文件夹中加载js文件,但似乎加载了webroot

中的所有js文件

我想要这个目录中的文件

webroot

在我的代码中我写道:

/webroot/js/signaturepad

所以它假设只读取这两个js文件,而在页面源中我可以看到webroot中已经加载了大量的js文件。我的js函数根本不起作用。

1 个答案:

答案 0 :(得分:0)

  

我想要这个目录中的文件

     

/根目录/ JS / signaturepad

启动路径不带斜线'/'和'js'文件夹名称,如:

echo $this->Html->script(array(
         'subfolder/your_js_file_name_here',
         'subfolder/your_js_file_name_here.min'
     ), array('inline' => false));

这会生成example.com/js/subfolder/your_js_file_name_here.js

之类的路径

如果你想在webroot文件夹中使用其他文件夹,例如:'frontend'然后用斜杠'/'开始路径。

echo $this->Html->script(array(
         '/frontend/your_js_file_name_here',
         '/forntend/your_js_file_name_here.min'
     ), array('inline' => false));

这会生成example.com/frontend/your_js_file_name_here.js

之类的路径