我正在使用它来让我的Ajax帖子调用在Laravel 5应用程序中工作:
<meta name="csrf-token" content="<?= csrf_token() ?>">
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
request = $.ajax({
url: "/user",
type: "post", success:function(data){
},
data: {'email': email} ,beforeSend: function(data){console.log(data);}
});
我可以在页面源中正确看到令牌呈现,但我仍然遇到内部服务器错误500并且Ajax调用失败。知道发生了什么吗?
编辑:
Ajax输出:
POST http://vidvalize.dev/user 500 (Internal Server Error)n.ajaxTransport.k.cors.a.crossDomain.send @ jquery-2.1.4.min.js:4n.extend.ajax @ jquery-2.1.4.min.js:4React.createClass.saveAndContinue @ script.js:37u @ react.min.js:12_.executeDispatch @ react.min.js:16a @ react.min.js:12s @ react.min.js:12c @ react.min.js:12r @ react.min.js:16d.processEventQueue @ react.min.js:12r @ react.min.js:15i.handleTopLevel @ react.min.js:15i @ react.min.js:15o.perform @ react.min.js:16d.batchedUpdates @ react.min.js:13i @ react.min.js:15v.dispatchEvent @ react.min.js:15
Object {readyState: 0}abort: (a){var b=a||u;return c&&c.abort(b),x(0,b),this}always: (){return e.done(arguments).fail(arguments),this}complete: (){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this}done: (){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this}error: (){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this}fail: (){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this}getAllResponseHeaders: (){return 2===t?e:null}getResponseHeader: (a){var b;if(2===t){if(!f){f={};while(b=gb.exec(e))f[b[1].toLowerCase()]=b[2]}b=f[a.toLowerCase()]}return null==b?null:b}overrideMimeType: (a){return t||(k.mimeType=a),this}pipe: (){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()}progress: (){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this}promise: (a){return null!=a?n.extend(a,d):d}readyState: 4responseText: "<!DOCTYPE html>↵<html>↵ <head>↵ <meta charset="UTF-8" />↵ <meta name="robots" content="noindex,nofollow" />↵ <style>↵ /* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */↵ html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}↵↵ html { background: #eee; padding: 10px }↵ img { border: 0; }↵ #sf-resetcontent { width:970px; margin:0 auto; }↵ .sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 }↵ .sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }↵ .sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }↵ .sf-reset .clear_fix { display:inline-block; }↵ .sf-reset * html .clear_fix { height:1%; }↵ .sf-reset .clear_fix { display:block; }↵ .sf-reset, .sf-reset .block { margin: auto }↵ .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }↵ .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }↵ .sf-reset strong { font-weight:bold; }↵ .sf-reset a { color:#6c6159; cursor: default; }↵ .sf-reset a img { border:none; }↵ .sf-reset a:hover { text-decoration:underline; }↵ .sf-reset em { font-style:italic; }↵ .sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif }↵ .sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; display: block; }↵ .sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; display: block; }↵ .sf-reset .exception_message { margin-left: 3em; display: block; }↵ .sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }↵ .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;↵ -webkit-border-bottom-right-radius: 16px;↵ -webkit-border-bottom-left-radius: 16px;↵ -moz-border-radius-bottomright: 16px;↵ -moz-border-radius-bottomleft: 16px;↵ border-bottom-right-radius: 16px;↵ border-bottom-left-radius: 16px;↵ border-bottom:1px solid #ccc;↵ border-right:1px solid #ccc;↵ border-left:1px solid #ccc;↵ }↵ .sf-reset .block_exception { background-color:#ddd; color: #333; padding:20px;↵ -webkit-border-top-left-radius: 16px;↵ -webkit-border-top-right-radius: 16px;↵ -moz-border-radius-topleft: 16px;↵ -moz-border-radius-topright: 16px;↵ border-top-left-radius: 16px;↵ border-top-right-radius: 16px;↵ border-top:1px solid #ccc;↵ border-right:1px solid #ccc;↵ border-left:1px solid #ccc;↵ overflow: hidden;↵ word-wrap: break-word;↵ }↵ .sf-reset a { background:none; color:#868686; text-decoration:none; }↵ .sf-reset a:hover { background:none; color:#313131; text-decoration:underline; }↵ .sf-reset ol { padding: 10px 0; }↵ .sf-reset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px;↵ -webkit-border-radius: 10px;↵ -moz-border-radius: 10px;↵ border-radius: 10px;↵ border: 1px solid #ccc;↵ }↵ </style>↵ </head>↵ <body>↵ <div id="sf-resetcontent" class="sf-reset">↵ <h1>Whoops, looks like something went wrong.</h1>↵ <h2 class="block_exception clear_fix">↵ <span class="exception_counter">1/1</span>↵ <span class="exception_title"><abbr title="Symfony\Component\Debug\Exception\FatalErrorException">FatalErrorException</abbr> in <a title="/home/vagrant/code/vidvalize/app/Http/Controllers/UserController.php line 5" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">UserController.php line 5</a>:</span>↵ <sp…>Illuminate\Pipeline\{closure}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php line 37" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">AddQueuedCookiesToResponse.php line 37</a></li>↵ <li>at <abbr title="Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse">AddQueuedCookiesToResponse</abbr>->handle() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 124" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 124</a></li>↵ <li>at <abbr title=""></abbr>call_user_func_array:{/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 124" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 124</a></li>↵ <li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php line 59" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">EncryptCookies.php line 59</a></li>↵ <li>at <abbr title="Illuminate\Cookie\Middleware\EncryptCookies">EncryptCookies</abbr>->handle() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 124" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 124</a></li>↵ <li>at <abbr title=""></abbr>call_user_func_array:{/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 124" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 124</a></li>↵ <li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php line 42" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">CheckForMaintenanceMode.php line 42</a></li>↵ <li>at <abbr title="Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode">CheckForMaintenanceMode</abbr>->handle() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 124" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 124</a></li>↵ <li>at <abbr title=""></abbr>call_user_func_array:{/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 124" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 124</a></li>↵ <li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 103" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 103</a></li>↵ <li>at <abbr title=""></abbr>call_user_func:{/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103}() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 103" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 103</a></li>↵ <li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->then() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php line 118" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Kernel.php line 118</a></li>↵ <li>at <abbr title="Illuminate\Foundation\Http\Kernel">Kernel</abbr>->sendRequestThroughRouter() in <a title="/home/vagrant/code/vidvalize/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php line 86" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Kernel.php line 86</a></li>↵ <li>at <abbr title="Illuminate\Foundation\Http\Kernel">Kernel</abbr>->handle() in <a title="/home/vagrant/code/vidvalize/public/index.php line 54" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">index.php line 54</a></li>↵ <li>at <abbr title=""></abbr>{main}() in <a title="/home/vagrant/code/vidvalize/public/index.php line 0" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">index.php line 0</a></li>↵ </ol>↵</div>↵↵ </div>↵ </body>↵</html>"setRequestHeader: (a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this}state: (){return c}status: 500statusCode: (a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this}statusText: "Internal Server Error"success: (){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this}then: (){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()}__proto__: Object
答案 0 :(得分:0)
您是否需要发送POST参数?
答案 1 :(得分:0)
内部服务器错误可能有很多原因。如果你可以发布完整的ajax响应,那么缩小问题会很有帮助。
但如果你认为,它与csrf_token
有关,请尝试将其作为请求数据发送,如下所示,
request = $.ajax({
url: "/user",
type: "post",
data: 'email=' + email + '&_token={{ csrf_token() }}',
beforeSend: function(data){console.log(data);},
success:function(data){}
});