0

In my Laravel Projects, I want to pass data from blade to my controller using Ajax.

But I am getting error

404 | Not Found

ajax

var pi_id = $(this).attr('href');    
$.ajax({
        url: "{{ url('purchase-invoice-detail') }}",
        type: "get",
        data: {
            'id': pi_id
        },
        success: function(response){ // What to do if we succeed                
                alert('ok'); 
        },
        error: function(response){
            alert('Error'+response);
        }
    });

route

Route::get('purchase-invoice-detail/{id}', 'PurchaseController@purchase_invoice_detail')->middleware('auth');

controller

public function purchase_invoice_detail($id)
{
    return 1;
}

Can't find the problem.

Anybody Help Please ?

7
  • 2
    Try this "{{ url('purchase-invoice-detail') }}" + '/' + pi_id as the url Commented May 26, 2022 at 7:43
  • @SahandMoghadam....same result....404 Not Found Commented May 26, 2022 at 7:47
  • 1
    So check the network tab on Chrome DevTools and post the Request Url. Commented May 26, 2022 at 7:53
  • Can you share html ? how you calling ajax i.e. click ? Commented May 26, 2022 at 7:54
  • @SahandMoghadam....it's done now.... Yours one is correct....I was missing double quoted comma...now it's ok.... But what is the problem og passing data through Ajax data object? Commented May 26, 2022 at 7:58

1 Answer 1

1

Please try this code

"{{ url('purchase-invoice-detail') }}"  + '/' + pi_id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.