The button counter on the homepage(after logging in) is supposed to increment count each time the button is pressed. Instead on pressing the button my code is redirecting to the authentication page for failed authentications. The Ajax code does not seem to be posting to the page. I dont understand why this is happening! Been stuck with this for 2 days. Can anyone help me out? I am relatively new to this.
Here is the View(html code). Its called like.blade.php
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<h1>Home Page</h1>
<?php $count=1; ?>
<div>
<form action="sessions/{count}" method="get" />
<input type=submit name="count" value="Counter" />
<br/>This button has been clicked
<span id="counter"><?php echo $count; ?></span> times.
</div>
<script type="text/javascript"
$(document).ready(function(){
$( '#counter').click(function(){
$.ajax({
type : 'POST',
url: "sessions.{count}",
data: like:like,
dataType: 'text',
async: true
success: function update_text(data) {
alert( "Counter clicked");
};
});
return false;
});
});
</script>
< /body>
</html >
This is the method where I am incrementing the counter and returning it :
Route::get('sessions.like', function () {
return View::make('sessions.like');
});
Route::get('sessions/{count}', function ($count) {
if (isset($count)) {
$count = $count + 1;
} else {
$count = 1;
}
return View::make('sessions.like')->with('sessions', $count);
});