我是Laravel 4的新手.我有一个页面,其中有3个标签(基本上是大的可点击的div)来加载不同的用户信息.我想做的是,我希望能够点击这些选项卡,发出jquery ajax请求,带回局部视图并使用该局部视图更新页面的一部分.我希望能够为每个标签做到这一点.
我点击了事件.我也尝试了不同的代码来完成ajax请求.出于某种原因,没有任何反应.我不知道我是否遗漏了route.php中的内容.有人可以给我一些关于如何做的代码吗?或者可能是其他一些想法?
我这样做了::
Route.php
Route::post('userInfo','UserController@showInfo');
Run Code Online (Sandbox Code Playgroud)
jqueryAjax:
$("divtoUpdatePartialView").click(function(){
$.ajax({
type: "POST",
url:Not Sure,
data: { id: userId }
}).done(function( msg ) {
alert( msg );
});
}
Run Code Online (Sandbox Code Playgroud)
我也试过使用Base Url,但没有任何反应.我在我的母版页上声明了一个ajax库.你能帮帮我还是给我一些其他想法?
非常感谢您的回答.我试过这种方式,这就是我所拥有的......
Route.php:
Route::get('user_Profile/userInfo', 'UserController@getshow');
Run Code Online (Sandbox Code Playgroud)
ajax:
var userId='1';
$.ajax({
type: "POST",
url: 'user_Profile/userInfo',
data: { id: userId }
}).done(function( msg ) {
alert( "the messageis "+msg );
});
My userController::
public function getshow()
{
return "No ajax";
if (Request::ajax()) {
return "yeahhhh";
$html=View::make('user.userProfile')->nest('partial', 'user.userInfoPartial')- >with('title',$title)->render();
}
}
Run Code Online (Sandbox Code Playgroud)
当我直接访问页面时,我收到"No ajax",但是当我尝试ajax-way时,没有任何反应.你能看到我错过的吗?
再次感谢你的帮助..