when i send data with ajax(jquery) i don't find the values in controller without form in laravel 5.1
Ad
This is my blade code:
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).ready(function(){
$(window).load(function(){
var topic_id = $("#topic").text();
var post = $("#post").text();
var url_id = "/posts/"+post+"/readStatus";
$("#topic").hide();
var users_id = $("#user").text();
$("#user").hide();
$.ajax({
async:true,
method:"post",
url:url_id,
topic_id:topic_id,
users_id:users_id,
processData: false,
contentType: false,
success:function(response){
console.log(response);
$("#message").html(response);
}
},"json");
});
});
Route::post('/posts/{post_id}/readStatus',function(){
if(Request::ajax()){
//In routes.php
$post = App\Post::find($post_id);
if(auth()->guest())
return "Not user Not read";
else{
$user = App\User::find(auth()->user()->id);
$post->attach($user);
return "Read";
}
//return Response::json(Request::all());
}
});
I get an 500 Internal server error .I found that $post_id in url doesn't hold any value inside.If I give any constant value in $post_id like 1,2... I get the answer.I don't want to use forms to achieve.I gave an ajax call as page loads.
Ad
Answer
Ad
You have to define $post_id
as your function argument.
Route::post('/posts/{post_id}/readStatus',function($post_id){
...
});
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad