【发布时间】:2018-03-23 08:37:00
【问题描述】:
我目前在 javascript 中使用 onload 调用文件。 它工作正常,我似乎无法让它在 Laravel 中工作,如果我加载一个 html 文件就可以了,但不是一个 php 文件。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#query").load("test.php");
});
</script>
</head>
<div id="query"><img src='https://m.popkey.co/163fce/Llgbv_s-200x150.gif'/></div>
<div id="query2"><img src='https://m.popkey.co/163fce/Llgbv_s-200x150.gif'/></div>
结果为空白。
test.php 文件位于 public 文件夹中,其中只有一个简单的回显:
<?php echo 'This is Working';
我在同一个文件夹中有一个test.html,它可以完美地返回我放入其中的内容,这似乎是 javascript 拉取 php 文件的问题。
如果我运行这个 url:https://domain/Home/public/test.html 它工作正常,如果我运行这个 url https://Domain/Home/public/test.php 它也工作正常。 test.php 回显 This is Working
【问题讨论】:
-
直接在浏览器中访问test.php会得到什么?你确定页面有效吗?好像和你的JS代码没有关系。
-
@jedrzej.kurylo,是的,我认为这与 Laravel 有关
-
然后发布你的 laravel 代码
-
@jedrzej.kurylo ,我更新了我的问题
-
正如@jedrzej.kurylo 已经问过的,
What do you get when you go to test.php directly in your browser?
标签: javascript php laravel-5