Support the ongoing development of Laravel.io →
Requests Input Forms
Last updated 2 years ago.
0

What does your JavaScript code look like?

0

Sorry for my later answer ... I tried some yhings. I have this : Form :

 <form method="POST" id="inner" class="ajax" action="{{ route('items.indication.insert') }}" accept-charset="UTF-8">
            <div class="form-group {{ ($errors->has('indication_name')) ? 'has-error' : '' }}">
                <input class="form-control" placeholder="indication_name" name="indication_name" type="text"  value="{{ Input::old('indication_name') }}">
            </div>
            
            <input name="_token" value="{{ csrf_token() }}" type="hidden">
            <button class="btn btn-primary sendbttn" value="{{ trans('site/buttons.create') }}" type="submit">Send</button>

    </form>

Javascript

 <script>

$(document).ready(function(){

        $('#innerbutton').click(function(e) {
        e.preventDefault();
        var dataString = form.serialize();

                var formAction = form.attr('action');
                var token =  $("input[name=_token]").val();
                var indication = $("input[name=indication_name]").val();
                $.ajaxSetup({
       headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
    });

            $.ajax({
            type: "get",
            url: formAction,
            data: dataString,
            cache: false,
            success: function(data) {
        console.log(data);
        console.log("success");
    },
    error: function(data) {  
        console.log(data);
        console.log("error");                 
    }
        },"json");
     });
 });

            </script>

Controller

use Illuminate\Http\Request; 

public function insert(Request $request)
{
    if($request->ajax()){
        return "AJAX";
    }
    return "HTTP";
}

But i have only a http response ..

0

Sign in to participate in this thread!

Eventy

Your banner here too?

kabdriver kabdriver Joined 6 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.