Your route is a get route. Try this :
Route::post('Moods', 'MoodsController@postMoods');
Hi! I'm trying to create a two button counter (using Javascript) that counts the clicks and then posts the final tally to my SQLite DB. (It actually pops each click's time onto an array, and then sends the length of the array and the array to the DB after a second of no clicks.) The Javascript logic has been tested and works, besides for the $.post function.
But I am receiving a 405 (Method Not Allowed) in the console and I have no idea why.
I'd really appreciate any help! Thank you!
Route:
Route::get('Moods', 'MoodsController@postMoods');
Script:
$(document).ready(function(){
var timer;
var happymood = [];
$('#Happy').click( function() {
clearTimeout(timer);
nothappymood = [];
happymood[happymood.length] = new Date($.now());
timer = setTimeout(function() {$.post('http://localhost:8000/Moods', {
valence: '0',
magnitude: happymood.length,
times: happymood.slice()
}); happymood =[];}, 1000);
});
var nothappymood = [];
$('#NotHappy').click( function() {
clearTimeout(timer);
happymood = [];
nothappymood[nothappymood.length] = new Date($.now());
timer = setTimeout(function() {$.post('http://localhost:8000/Moods', {
valence: '1',
magnitude: nothappymood.length,
times: nothappymood.slice()
}); nothappymood =[];}, 1000);
});
});
Controller:
class MoodsController extends Controller
{
public function postMoods(Request $request) {
$valence = $request->input('valence');
$magnitude = $request->input('magnitude');
$times = $request->input('times');
}
}
HTML:
<button class="btn btn-primary" id='Happy' type="submit">Happy</button>
<button class="btn btn-primary" id='NotHappy' type="submit">Not Happy</button>
Table:
Schema::create('moods', function (Blueprint $table) {
$table->increments('id');
$table->boolean('valence');
$table->integer('magnitude')->unsigned();
$table->datetime('times');
});
Please or to participate in this conversation.