i'm trying to create a ajax controller to switch locate, here are the code:
frontend jquery :
<script language="javascript">
$( "#lang" )
.change(function () {
$.ajax({
method: "POST",
url: "{{ url('/lang') }}",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
})
</script>
controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class LangController extends Controller
{
//
public function Lang () {
/*$rules = [
'language' => 'in:en,zh-tw' //list of supported languages of your application.
];*/
App::setLocale('zh-tw');
return 'success';
}
}
route:
Route::post('lang', 'LangController@lang');
The result is internal server error 500, the App::setLocale('zh-tw'); run well in other non-ajax controller, everyone know what's wrong with that?
5XX level error- generally occurs at server level. So it should have been logged - either inapacheor inapplication. However - you can enableE_ALLinphp.inierror setting cause without checking what the error is - it's hard to solve.\App:setLocale()instead ofApp:setLocale(). The difference is thebackslashbefore - which denotes this App is inglobal namespaceoutside the namespace of the controller.