Rolando Abu
Rolando Abu

Reputation: 37

{message: "", exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…}

I'm a newbie in laravel. I want to add a product using ajax method but I'm getting this error, in the console: POST 404 NOT FOUND. In the network, I'm getting this error message:

{message: "", exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…}
exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
file: "C:\Users\rolan\Desktop\Laravel Tutorial\Fims\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php"
line: 179
message: ""
trace: [{,…}, {,…}, {,…}, {,…}, {,…},…]

Here is my ajax code:

<script>
$(document).ready(function(){
    // alert("working");
    $("#btn").click(function(){
        var prodName = $("#prodName").val();
        var rate = $("#rate").val();
        var beginningQuantity = $("#beginningQuantity").val();
        var token = $("#token").val();

        $.ajax({
            type: "POST",
            data: "prodName=" + prodName + "&rate=" + rate + "&beginningQuantity=" + beginningQuantity + "&_token" + token,
            url: "<?php echo url('/saveProduct') ?>",
            success: function(data){
                console.log(data);
            }
        });
    });
});
</script>

here's the line 179 codes

<input type="hidden" value="{{csrf_token()}}" id="token">

here's the controller code

public function saveProduct(Request $request){
    return $request;
}

here's the route

Route::get('/adminIndex',"adminIndexController@count");
Route::get('/adminInventory',"adminInventoryController@count");

Upvotes: 2

Views: 9731

Answers (3)

Obi Dennis Chizolu
Obi Dennis Chizolu

Reputation: 108

For me using hyphens or underscore instead of camel case did the trick

Route::post('/save-product', 'adminInventoryController@saveProduct');

Upvotes: 0

Laslomcd
Laslomcd

Reputation: 31

NotFoundHttpException usually means that your route doesn't exist. Check your web.php file and make sure that there is a route there for '/saveProduct' and that it is a post route and not a get route.

You will need a route like this:

Route::post('/saveProduct', 'adminInventoryController@saveProduct');

Upvotes: 3

RhysD
RhysD

Reputation: 1647

Ok so I'm not sure if this has anything to do with it, but it seems as though you may have incorrectly typed it into your question, but you have written:

$.ajax({
    type: "POST",
    data: "prodName=" + prodName + "&rate=" + rate + "&beginningQuantity=" + beginningQuantity + "&_token" + token,
    url: "<?php echo url('/saveProduct') ?>",
    succes: function(data){
        console.log(data);
    }
});

Is it meant to say success: instead of succes:?

Upvotes: 1

Related Questions