Bak*_*son 6 javascript php ajax laravel
正如标题所说,我试图使用ajax请求动态加载视图中的内容.我知道如果你正在使用html元素,这可以做到("#div_place").html(<p>...).问题在于我想将一些php/blade对象加载到div中.这是可能的,还是有不同的方法来实现我想要的结果.
这很简单。假设您使用的是jQuery ...
创建一个将响应AJAX调用并返回HTML片段的路由
Route::get('test', function(){
// this returns the contents of the rendered template to the client as a string
return View::make("mytemplate")
->with("value", "something")
->render();
});
Run Code Online (Sandbox Code Playgroud)在您的JavaScript中:
$.get(
"test",
function (data) {
$("#my-content-div").html(data);
}
);
Run Code Online (Sandbox Code Playgroud)Bak*_*son -2
经过更多挖掘后,我发现这帮助我解决了问题。
您必须使用.load("url/page/...")via jquery,然后在routes.php文件中设置一条路线,该文件显示一个包含需要加载的数据的视图,例如
Route::get('/url/page/...', function(){
return View::make('test');
});
Run Code Online (Sandbox Code Playgroud)
这将返回需要动态加载的必要 php 代码,欢呼。
| 归档时间: |
|
| 查看次数: |
11672 次 |
| 最近记录: |