I can't seem to get an ajax call to work. The ajax post request is supposed to do some processing and return a success message. I have removed all the codes for processing and returning just the success message yet nothing is returned on the console. This is my code
My View
function payWithPaystack(){
var handler = PaystackPop.setup({
},
callback: function(response){
alert('success. transaction ref is ' + response.reference);
var userId = '<?php echo $userId; ?>';
console.log(userId);
$.post('/payment/'+userId, {psid: userId}, function (data) {
console.log(data);
})
}
});
My route
Route::match(['post','get'], '/payment/{userId}', 'PaymentController@index');
My controller
public function index(Request $request, $userId){
$method = $request->isMethod('post');
if($method){
$message='User disabled!!';
$success='Disabled';
echo json_encode(array('message'=>$message,'success'=>$success));
}else{
return view('payment', compact('userId'));
}
}
Please what am I doing wrong here?
Edit: When I took the ajax outside the callback, it works so I am guessing the callback ain't allowing the ajax call. How do I resolve this?