Hey,
What you are trying to achieve is quite easy. I am assuming you are running laravel via the command
php artisan serve
<!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>
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;
});
Route::controller('apps', 'AppController');
public function postBikelockersRemovedeleteuser() {
$userID = Input::get('value');
return Response::json($userID);
}
Hope this helps
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community