I'm sending value named text
from my <script>
tag that is in a .blade.php
file to controller by using POST
Ajax request. If I do not write $.post
function then it gives me output of text value in console. BUT when I write this Ajax request to send data to controller value do not pass. In short, I want to pass value from View to Controller and I am unable to do that. I have tried all YouTube tutorials and previous Stack Overflow questions. I also visited Laracasts but problem is not solved. Am I doing something wrong? Please help. Thank you.
shopReq.blade.php:
{{csrf_field()}}
<script>
$(document).ready(function(){
$('.ourItem').click(function(event){
var text=$(this).text();
$('#addItem').val(text);
console.log(text);
$.post('shopReq',{'text':text,'_token':$('input[name=_token]').val()}),function(data){
console.log(data);
});
});
});
</script>
Web.php:
Route::post('shopReq','UserController@special');
Controller:
class UserController extends Controller
{
public function special(Request $request){
$articles = DB::table('shoppingtrips')->get();
echo"DONE";
// return $request->all();
}
}