After this line:
var id = $(this).data("id");
If you
alert(id);
Does it give you the id? And
This
return redirect()->back()
->with('success',' Updated successfully.');
Sent back a response json.
I want to pass id from my blade form and store that id to another table,
am try like this but get this error
my blade form
<td>
<meta name="csrf-token" content="{{ csrf_token() }}">
<a href="#" data-id="{{$dt->id}}" id="add_btn" class="btn btn-sm btn-default add_btn ">Issue</i>
</a> </td>
</tr>
@endforeach
</tbody>
my ajax
$(".add_btn").click(function(e){
e.preventDefault();
var id = $(this).data("id");
var token = $("meta[name='csrf-token']").attr("content");
$.ajax(
{
url: "addUnit/"+id,
type: 'POST',
data: {
"id": id,
"_token": token,
},
dataType: 'json',
success: function(data) {
console.log('SUCCESS: ', data);
},
error: function(data) {
console.log('ERROR: ', data);
},
});
});
my controller public function addUnit_to_issued(Request $request){
$id = $request->input('id');
// store id data to another table here
dd($id);
return redirect()->back()
->with('success',' Updated successfully.');
}
error
ERROR: {readyState: 4, setRequestHeader: ƒ, getAllResponseHeaders: ƒ, getResponseHeader: ƒ,
overrideMimeType: ƒ, …}
POST http://127.0.0.1:8000/store/addUnit/1 404 (Not Found)
public function addUnit_to_issued(Request $request, $id)
{
IssuedUpload::firstOrCreate(['unit_id' => $id]);
if ($request->wantsJson()) {
return response()->json([
'success' => 'Updated successfully.'
]);
}
return redirect()->back()->with('success',' Updated successfully.');
}
Documentation: https://laravel.com/docs/7.x/eloquent#other-creation-methods
Please or to participate in this conversation.