weixin_33699914 2017-05-27 17:34 采纳率: 0%
浏览 26

Laravel 5.0 Ajax无法正常工作

I have mistake with firebug : "500 (Internal Server Error)".

I begin with Ajax and I would like understand a simply thing:

$("#boutonRecherche").click(function () {
$.ajax({
url : "/recherche", //I have tried rechercheController.php and ...
                     //...Http/Controllers/Phases/RechercheController.php
type : "POST",
data : '&controle=1',//after comments I found this lines triggers error in
                     //...firebug
dataType : "html"
});
});
  1. What is the best path for the url ?

  2. How to fix "500 (Internal Server Error)"

View code:

{!! Form::open(['url'=>'recherche']) !!}
{!! Form::submit('solaire',['class'=>'btn btn-primary', 'name'=>'recherche', 
'id'=>'boutonRecherche']) !!}
{!! Form::close() !!}

My paths :

  1. My Controller Http/Controllers/Phases/RechercheController.php

  2. My View public/resources/views/phases/recherche.blade.php

  3. My JS dans public/script.js

Thanks in advance ;)

  • 写回答

1条回答 默认 最新

  • csdn产品小助手 2017-05-27 18:08
    关注

    POST request needs CSRF token.
    When you are sending form, add to data object in AJAX field {_token: csrfToken}.

    The csrfToken you can parse from form or from <head> where you create <meta name="csrf_token" content="{{csrf_token()}}"> field.

    If you want to send GET param, append it to url, so url : "/recherche?controle=1"

    评论

报告相同问题?

悬赏问题

  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题