XMLHttpRequest无法加载javascript:void(0)

时间:2017-02-08 04:08:30

标签: jquery ajax laravel

我有这个ajax请求

var token = '{{ Session::token() }}';
var urlAdd = '{{ route('postSocialWorker') }}';

$("#save").click(function () {
    $.ajax({
        type: 'post',
        url:  urlAdd,
        data:{
            'name': $('input[name=name]').val(),
            'email': $('input[email=email]').val(),
            'store_id': $("select['name=store_id']").val(),
            _token: token
        },
        success: function (data) {
            if ((data.errors)) {
                $('.error').removeClass('hidden');
                $('.error').text(data.errors.name);
            }
            else {
                $('.error').addClass('hidden');
                $('#table').append("<tr class='item" + data.id + "'><td>" + data.id + "</td><td>" + data.name + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-edit'></span> Edit</button> <button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-trash'></span> Delete</button></td></tr>");
            }
        },
    });

这是我的控制器

public function addSocialWorker(Request $request)
{
   $rules = array(
    'name' => 'required|alpha_num',
    'email' => 'required|email|unique:users',
    'store_id' => 'required|numeric'
    );

   $validator = Validator::make(Input::all(), $rules);
   if ($validator->fails())
    return Response::json(array(
        'errors' => $validator->getMessageBag()->toArray()
        ));
else {
    $data = new User();
    $data->name = $request->name;
    $data->email = $request->email;
    $data->status = 1;
    $data->role_id = 2;
    $data->store_id= $request->store_id;
    $data->save();
    return response()->json($data);
}

}

但我收到此错误

  

XMLHttpRequest无法加载javascript:void(0)。交叉原始请求   只支持协议方案:http,data,chrome,   chrome-extension,https,chrome-extension-resource。

有什么想法吗?我正在使用laravel

0 个答案:

没有答案