我有这个HTML
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Select your Language<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{{URL::route('language')}}" class="choose-language" id="french" data-value="fr">Français</a></li>
<li><a href="{{URL::route('language')}}" class="choose-language" id="english" data-value="en">English</a></li>
</ul>
点击应该将数据传递给这个AJAX:
<script>
$(document).ready(function(){
$('.choose-language').on('click', function()
{
var selectedlanguage = $(this).data('value');
$url = '{{URL::route('languagechooser')}}';
$.post($url, {'locale': selectedlanguage},function(data){
}); // HERE FINISHES THE $.POST STUFF
}); //HERE FINISHES THE CLICK FUNCTION
}); // HERE FINISHES THE DOCUMENT AND READY STUFF
</script>
这个Ajax应该将该值传递给此Controller:
class LanguageController extends Controller {
public function languagechooser()
{
\Session::set('locale', \Input::get('locale'));
return\Redirect::back();
}
}
但它没有将值传递给该控制器。它作为参数接收时变为NULL。 (因为我var_dump(Session :: getLocale());我得到NULL 确认该值在单击HTML标签时传递给ajax(我点击了警告并显示了它)。但在那之后,我不明白为什么控制器没有得到任何东西。
路线是:
Route::get('language', array(
'as'=>'language',
'uses'=>'LanguageController@languagechooser'
));
Route::post('home', array(
'as' =>'languagechooser',
'uses' =>'LanguageController@languagechooser'
));
注:
Firebug Net XHR返回:零请求