weixin_33670713 2015-06-19 13:56 采纳率: 0%
浏览 18

laravel 5 Ajax没有形式

Im having problems with sending an ajax request using laravel 5.

This is what kicks of the ajax request when clicked.

<td>
    <i data-service="{{$performer['serviceID']}}" class="fa fa-eye"></i>{{$performer['name'] }}
</td>

Ajax code

$(function() {
    $('.fa-eye').click(function () {
        var service = $(this).attr('data-service');

        jQuery.ajax({
            crossDomain: true,
            url: "/addWatchList",
            beforeSend: function (xhr) {
                var token = $('meta[name="csrf_token"]').attr('content');
                console.log(token);
                if (token) {
                    return xhr.setRequestHeader('X-CSRF-TOKEN', token);
                }
            },
            type: "POST",
            dataType: "json",
            processdata: true,
            data: {
                service: service
            },
            success: function( data ) {
               alert(data);
            },
            error: function (error) {
                console.log(error);
                //alert("xhr=" + xhr + " b=" + b + " c=" + c);
            }
        });
        alert('went past ajax');
    });
});

Now my ajax request isn't even reaching my controller.

The error i get is xhr=[object Object] b=parsererror c=SyntaxError: Unexpected token <

Does anyone know why this is happening?

  • 写回答

1条回答 默认 最新

  • weixin_33735676 2015-06-19 16:34
    关注

    Maybe it's not an answer to your question, but if you want to pass the token, just add

    "_token": "{{ csrf_token() }}"
    

    to your data.

    评论

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”