jeudi 6 septembre 2018

I can't seem to get an ajax post request to work

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire