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

Hey,

What you are trying to achieve is quite easy. I am assuming you are running laravel via the command

php artisan serve

View template

<!DOCTYPE html>
<html>
<head>
    <title>Testing</title>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
    
    <form name="sub">
        <input name="val" type="text" placeholder="Enter a value"/>
        <input type="submit" value="Submit"/>
    </form>

    <script>
        $("form[name=sub]").submit(function(event) {
            $.ajax({
                url: 'http://localhost:3000/apps/bikelockers-removedeleteuser',
                data: {value: $("input[name=val]").val()},
                type: 'POST'
            }).promise().then(function(data) {
               console.log(data);
            });
            // Stop the forms default action method
            event.preventDefault();
        });
    </script>
</body>
</html>

filters.php

App::before(function($request)
{
    if($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
        $statusCode = 204;

        $headers = [
            'Access-Control-Allow-Origin'      => '*',
            'Access-Control-Allow-Methods'     => 'GET, POST, OPTIONS',
            'Access-Control-Allow-Headers'     => 'Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since',
            'Access-Control-Allow-Credentials' => 'true'
        ];

        return Response::make(null, $statusCode, $headers);
    }
});


App::after(function($request, $response)
{
    $response->headers->set('Access-Control-Allow-Origin', '*');
    $response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
    $response->headers->set('Access-Control-Allow-Headers', 'Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since');
    $response->headers->set('Access-Control-Allow-Credentials', 'true');
    return $response;
});

routes.php

Route::controller('apps', 'AppController');

AppController.php

    public function postBikelockersRemovedeleteuser() {
        $userID = Input::get('value');
        return Response::json($userID);
    }

Hope this helps

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.