lundi 1 octobre 2018

Laravel Ajax not sending data to controller

I'm trying to send data from a form with ajax to the controller. The Ajax is executing but the function in controller not. I do not get any error, I just get the formdata and YES! printed but after that nothing happens. Can anyone check what is wrong?

This is the Ajax

$(document).ready(function() {
  $("#sissend").click(function(e){
        e.preventDefault();
        var formdata =  $('#sistrixKw').serializeArray();
        console.log(formdata);

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        url: "/sistrix",
        type: "POST",
        data: {'formdata' : 'formdata'},

        success: function(){
            console.log("YES!")

        },

    });     
});

This is the form in the view (in a Modal):

<form method="post"  id="sistrixKw" name="sistrixKw" enctype="multipart/form-data">
                        <input type="hidden" name="_token" id="token" value="">
                        <input type="hidden" name="jid" id="jid">
                        <div class="row">
                            <div class="form-group">
                                <label for="domain" class="col-sm-3 control-label">Domain</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="domain" name="domain"  
value="https://www.baubau.org">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label for="date" class="col-sm-3 control-label">Date</label>
                                <div class="col-sm-9">
                                    <label class="radio-inline">
                                        <input type="radio"  id="now" name="week" class="week" value="now" 
checked> This Week
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" id="lastweek" 
                      name="week" class="week" value="last week"> Last Week
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label for="kwnum" class="col-sm-3 control-label">Keywords 
ammount</label>
                                <div class="col-sm-9">
                                    <input  type="number" min="0" class="form-control" id="kwnum" 
name="kwnum" value="2">
                                </div>
                            </div>
                        </div>
                    </form>

This is the function that should receive the data from Ajax but is not:

public function sendtosistrix(Request $request)
    {

        if($request->ajax())
        {
                var_dump($request->all());
                exit;
         }

    [...]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire