我对laravel和laravel-5很新。当我执行POST请求时,我在firebug控制台中获得200响应登录请求。
routes.php文件
Route::group
(
[
'prefix' => '/',
'namespace' => 'Landing'
],
function()
{
Route::controller('', 'WelcomeController');
}
);
WelcomeController.php
public function postUserContact()
{
print_r($_POST);
}
Ajax请求:
$.ajax({
url : window.location.protocol + "//" + window.location.host + '/user-contact',
type : 'POST',
async : true,
cache : false,
processData : true,
data : {name:name,email:email,message:message},
success : function (returnedData)
{console.log(returnedData)}
});
如果有任何错误,请纠正我
答案 0 :(得分:0)
试一试:
routes.php文件
Route::get('/', array('as' => 'index', 'uses' => 'WelcomeController@getIndex'));
Route::post('/', array('as' => 'ajaxdata', 'uses' => 'WelcomeController@ajaxdata'));
WelcomeController.php
public function getIndex() {
return View::make('yourapp.index');
// resources/views/yourapp/index.blade.php
}
public function ajaxdata() {
if (Request::ajax()) {
$data = Input::all();
//you access all data from ajax
}
}
index.blade.php中的Ajax
$.ajax({
url: 'ajaxdata', //add url what you specify in routes.php
...