jeudi 21 juin 2018

Laravel ajax URL issue

I'm new to Laravel and using Ajax for some functionalities.

//Route
Route::post('some/thing/','Controller@Method');

//jQuery
$('.some_class').click(function(){
        var var1 = $('.some').val();
        var val2 = $(".another").val();
        var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
        $.ajax({
            //this part
            url: "some/thing/",
            type:"POST",
            data: { var1: var1,val2: val2,_token: CSRF_TOKEN},
            success:function(response){
               console.log("working");
            },
            error:function(){
                console.log("error");
            }
        });
    });

//controller
public function Method(Request $object){
   if(isset($_POST['val1'])){//do something}
}

problem is in the URL parameter of AJAX. When I'm giving value to the url i.e some/thing/, it gives me 404 error showing https://ift.tt/2K7n7Vj not found and when I'm keeping url value blank then it's working. But then i don't think it's a good practice to do like this.

I have seperate .js file in public folder. Controller in different and blade file in different directory. Laravel version 5.6.22

thank you.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ytEnCC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire