我正在尝试获取一个 html 表以在 ajax 调用时返回。 路线: 调用页面上的ajax: 控制器: 看法: 我在 json.html 数据中没有得到任何东西。 没有。 如果在控制器中我说: 这工作得很好。 如何从 Laravel 5 中的 ajax 调用返回视图。 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
当我尝试在laravel中使用ajax时,显示以下错误,
{“ message”:“”,“ exception”:“ Symfony \\ Component \\ HttpKernel \\ Exception \\ HttpException”,“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Exceptions \\ Handler.php“,” line“:203,” trace“:[{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Exceptions \\ Handler.php “,” line“:175,” function“:” prepareException“,” class“:” Illuminate \\ Foundation \\ Exceptions \\ Handler“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ app \\ Exceptions \\ Handler.php“,” line“:49,” function“:” render“,” class“:” Illuminate \\ Foundation \\ Exceptions \\ Handler“,” type“:”->“ },{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php”,“ line”:83,“ function”:“ render”,“ class “:”“ App \\ Exceptions \\ Handler”,“类型”:“->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php “,” line“:55,” function“:” handleException“,” class“:” Illuminate \\ Rout ing \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ View \\ Middleware \\ ShareErrorsFromSession.php“,” line“:49,” function“:” Illuminate \\ Routing \\ {closure}“,” class“:” Illuminate \\ Routing \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php“,” line“:151,” function“:” handle“,” class“:” Illuminate \\ View \\ Middleware \\ ShareErrorsFromSession“ ,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php”,“ line”:53,“ function“:” Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Session \\ Middleware \\ StartSession.php“,” line“:63,” function“:” Illuminate \\ Routing \\ {closure}“,” class“:” Illuminate \\ Routing \\ Pipeline“ ,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ larave l \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php“,” line“:151,” function“:” handle“,” class“:” Illuminate \\ Session \\ Middleware \\ StartSession“,” type“:”-> “},{”文件“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php“,” line“:53,” function“:” Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Cookie \\ Middleware \\ AddQueuedCookiesToResponse.php”,“行”:37,“功能”:“ Illuminate \\ Routing \\ {closure}”,“ class”:“ Illuminate \\ Routing \\ Pipeline”,“ type”:“-> “},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php“,” line“:151,” function“:” handle“,” class“:” Illuminate \\ Cookie \\ Middleware \\ AddQueuedCookiesToResponse“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php”,“行”:53,“功能”:“ Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Cookie \\ Middleware \\ EncryptCookies.php”,“行”:59,“功能”:“ Illuminate \\ Routing \\ {closure}”,“类”:“ Illuminate \\ Routing \\ Pipeline”,“类型”:“-> “},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php“,” line“:151,” function“:” handle“,” class“:” Illuminate \\ Cookie \\ Middleware \\ EncryptCookies“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php“,” line“:53,” function“:” Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{”文件“:”“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php”,“ line”:104,“ function”:“ Illuminate \\ Routing \\ {closure}”,“ class“:” Illuminate \\ Routing \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Router.php”,“行”:667,“功能”:“然后”,“类”:“ Illuminate \\ Pipeline \\ Pipeline”,“类型”:“-> “},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Router.php“,” line“:642,” function“:” runRouteWithinStack“,” class“:” Illuminate \\ Routing \\ Router“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Router。 php”,“行”:608,“功能”:“ runRoute”,“类”:“ Illuminate \\ Routing \\ Router”,“类型”:“->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Router.php“,” line“:597,” function“:” dispatchToRoute“,” class“:” Illuminate \\ Routing \\ Router“,” type“ :“->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Kernel.php”,“行”:176,“功能” :“调度”,“类别”:“ Illuminate \\ Routing \\ Router”,“类型”:“->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php“,” line“:30,” function“:” Illuminate \\ Foundation \\ Http \\ {closure}“,” class“:” Illuminate \\ Foundation \\ Http \\内核”,“类型”:“->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ fideloper \\ proxy \\ src \\ TrustProxies.php”,“行”:57,“功能” :“ Illuminate \\ Routing \\ {closure}”,“ class”:“ Illuminate \\ Routing \\ Pipeline”,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php”,“行”:151,“功能”:“句柄”,“类”:“ Fideloper \\ Proxy \\ TrustProxies”,“类型”:“->”} ,{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php”,“ line”:53,“ function”:“ Illuminate \\ Pipeline \\ {closure }“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Middleware \\ TransformsRequest.php“,” line“:31,” function“:” Illuminate \\ Routing \\ {closure}“,” class“:” Illuminate \\ Routing \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline。 php“,” line“:151,” function“:” handle“,” class“:” Illuminate \\ Foundation \\ Http \\ Middleware \\ TransformsRequest“,” type“:”->“},{” file“:” C :\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php“,” line“:53,” function“:” Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Middleware \\ TransformsRequest。 php“,” line“:31,” function“:” Illuminate \\ Routing \\ {closure}“,” class“:” Illuminate \\ Routing \\ Pipeline“,” type“:”->“},{” file“: “ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php”,“ line”:151,“ function”:“ handle”,“ class”:“ Illuminate \\ Foundation \\ Http \\ Middleware \\ TransformsRequest“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php“,” line“:53,” function“:” Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“ ,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Middleware \\ ValidatePostSize.php”,“行” :27,“ function”:“ Illuminate \\ Routing \\ {closure}”,“ class”:“ Illuminate \\ Routing \\ Pipeline”,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php“,” line“:151,” function“:”句柄“,” class“:” Illuminate \\ Foundation \\ Http \\ Middleware \\ ValidatePostSize“ ,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php”,“ line”:53,“ function“:” Illuminate \\ Pipeline \\ {closure}“,” class“:” Illuminate \\ Pipeline \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\供应商\\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Middleware \\ CheckFo rMaintenanceMode.php“,” line“:62,” function“:” Illuminate \\ Routing \\ {closure}“,” class“:” Illuminate \\ Routing \\ Pipeline“,” type“:”->“},{”文件“:”“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php”,“ line”:151,“ function”:“ handle”,“ class”:“ Illuminate \\ Foundation \\ Http \\ Middleware \\ CheckForMaintenanceMode“,”类型“:”->“},{”文件“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ Pipeline.php“ ,“行”:53,“功能”:“ Illuminate \\ Pipeline \\ {closure}”,“ class”:“ Illuminate \\ Pipeline \\ Pipeline”,“ type”:“->”},{“ file”:“ C :\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Pipeline \\ Pipeline.php“,” line“:104,” function“:” Illuminate \\ Routing \\ {closure}“,” class“:” Illuminate \\ Routing \\ Pipeline“,” type“:”->“},{” file“:” C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Kernel.php“ ,“行”:151,“功能”:“然后”,“类”:“ Illuminate \\ Pipeline \\ Pipeline”,“类型”: “->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Foundation \\ Http \\ Kernel.php”,“行”:116,“功能”: “ sendRequestThroughRouter”,“类”:“ Illuminate \\ Foundation \\ Http \\ Kernel”,“ type”:“->”},{“ file”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ public \\ index.php”, “行”:55,“函数”:“句柄”,“类”:“ Illuminate \\ Foundation \\ Http \\ Kernel”,“类型”:“->”},{“文件”:“ C:\\ xampp \\ htdocs \\ TravelAssistant \\ server.php“,” line“:21,” function“:” require_once“}]}
我的控制器代码是
public function getPublicAttraction(Request $request)
{
return response(['msg'=>'success']);
}
阿贾克斯电话,
<script>
function getAttraction()
{
var pass= {'_token':$('meta[name="csrf-token"]').attr('content')
};
$.ajax({
type:'POST',
url:'{{route("Attractions")}}',
datatype:'json',
data: pass,
success:function(data){
$("#public_attractions").html(data.msg);
}
}).fail(function(jqXHR, textStatus, error){
$("#public_attractions").html(jqXHR.responseText);
});
}
$(document).ready(function(){
getAttraction();
});
</script>
带有csrf令牌的元标记,
<meta name="csrf-token" content="!!{csrf_token()}!!">
路由文件web.php条目,
Route::post('/getAttractions','AjaxController@getPublicAttraction')->name('Attractions');
我想我被困住了,请帮忙。
为什么要重新发明行之有效的东西。
刀片中的第一个令牌应如下所示:(无论出于何种原因,您都有额外的!!)
<meta name="csrf-token" content="{{ csrf_token() }}">
2nd将此代码放在主刀片中的某个位置:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
好的,除了CSRF元标记的方式外,其他一切看起来都不错,因为您不需要转义csrf令牌中的任何内容,因此打印令牌的正确方法将是: <!-- CSRF Token --> <meta name="csrf-token" content="{{ csrf_token() }}">
Token- <!-- CSRF Token --> <meta name="csrf-token" content="{{ csrf_token() }}">
这是我无法给您的最佳猜测,因为您没有提供响应的HTTP状态是什么,也不提供抛出异常的哪种情况,异常消息也为空所以..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.