Laravel Blade 使用 jquery 加载方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26557747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel blade use jquery load method
提问by JordyvD
Is there any way to use jquery to render the webpage? Blade keeps reloading the whole page, which is really annoying when you have music running on the website (It will keep stopping). Normally i would use Jquery's .load("HTMLPAGE") method but this doesn't seem to work.
有什么办法可以使用jquery来渲染网页吗?Blade 不断重新加载整个页面,当您在网站上运行音乐时,这真的很烦人(它会一直停止)。通常我会使用 Jquery 的 .load("HTMLPAGE") 方法,但这似乎不起作用。
What i did so far: http://pastebin.com/0u1JeHD0
到目前为止我做了什么:http: //pastebin.com/0u1JeHD0
What happens is: first jquery does its thing & after that laravel/blade reloads the whole view.
发生的事情是:首先 jquery 做它的事情,然后 laravel/blade 重新加载整个视图。
From what i understand is that you can extend views to replace parts of said views but when i try this it still reloads the whole page.
据我了解,您可以扩展视图以替换部分所述视图,但是当我尝试这样做时,它仍然会重新加载整个页面。
If you have any questions, please ask as i have a hard time explaining what i exactly mean.
如果您有任何问题,请提问,因为我很难解释我的确切意思。
PS: I did not know i needed to say this but: if you are here to get rude, just get off. I'm asking a question and as far as I know this is a site where you can do such things.
PS:我不知道我需要这么说,但是:如果你在这里粗鲁,请下车。我在问一个问题,据我所知,这是一个您可以执行此类操作的网站。
回答by António Pinto
This was not tested, but should work:
这没有经过测试,但应该可以工作:
On your routes.php file:
在您的 routes.php 文件中:
Route::get('/yoururl', function() {
return View::make('view-to-load');
});
// Laravel 5^
Route::get('/yoururl', function() {
return view('view-to-load');
});
On your app.js (or whatever your javascript file is named):
在您的 app.js(或任何您的 javascript 文件名称)上:
$(document).ready(function() {
$('#containner').load('/yoururl');
});
This way your blade template with the file name view-to-load.blade.phpshould be loaded in the HTML elemente with the ID containner.
这样你的文件名刀模板视图到load.blade.php应在HTML元素系列的ID被加载containner。
Hope I had helped :)
希望我有所帮助:)
Note: This might not be the most correct way of doing this, but its simple enought, that was the point.
注意:这可能不是最正确的方法,但它足够简单,这就是重点。