Home > Software design >  Why jquery is not working when there is parameter on route in laravel
Why jquery is not working when there is parameter on route in laravel

Time:10-28

When the route is

Route::get('/Bin',[BinCardController::class, 'Index']);

Jquery load and work.

But When Route::get('/Bin/{steak}',[BinCardController::class, 'Index']); jquery not load.

Even if I put http://127.0.0.1:5000/bin/ . For the last '/' jquery is not load . But if I keep it only http://127.0.0.1:5000/bin then jquery load and work

import jquery app.blade.php for my application:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>@yield('title')</title>
        <link href="https://fonts.googleapis.com/css2?family=Roboto Condensed:ital,wght@0,400;1,400&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
        <link rel="icon" href="img/mdb-favicon.ico" type="image/x-icon" />
        <link  href="{{asset('css/bootstrap.min.css')}}" rel="stylesheet">
        <link href="{{asset('css/mdb.min.css')}}" rel="stylesheet">
        <link href="{{asset('css/sidenav.css')}}" rel="stylesheet">
        <link href="{{asset('css/style.css')}}" rel="stylesheet">
        <link href="{{asset('css/responsive.css')}}" rel="stylesheet">
        <link href="{{asset('css/datatables.min.css')}}" rel="stylesheet">
        <link href="{{asset('css/datatables-select.min.css')}}" rel="stylesheet">
        <link href="{{asset('css/public7ade.css')}}" rel="stylesheet">
    {{--    13.10.2021--}}
        <link href="{{asset('css/hover-menu.css')}}" rel="stylesheet">
        <link href="{{asset('css/fonts.css')}}" rel="stylesheet">
        <link href="{{asset('css/custom-css-for-input.css')}}" rel="stylesheet">
    
        <link href="{{asset('mdb.rtl.min.css')}}" rel="stylesheet">
    <link href="{{asset('')}}" rel="stylesheet">
    <link href="{{asset('')}}" rel="stylesheet">
    <link href="{{asset('')}}" rel="stylesheet">

    @yield('script')





</head>
<body class="backgroundLogo">
@include('Layout.menu')
@yield('content')


<script src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="{{asset('js/popper.min.js')}}"></script>
<script type="text/javascript" src="{{asset('js/bootstrap.js')}}"></script>
<script type="text/javascript" src="{{asset('js/mdb.min.js')}}"></script>
<script src="{{asset('js/jquery.slimscroll.js')}}"></script>
<script src="{{asset('js/sidebarmenu.js')}}"></script>
<script src="{{asset('js/mdb.min.js')}}"></script>
<script src="{{asset('js/sticky-kit.min.js')}}"></script>
<script src="{{asset('js/custom.min-2.js')}}"></script>
<script src="{{asset('js/datatables.min.js')}}"></script>
<script src="{{asset('js/datatables-select.min.js')}}"></script>
<script src="{{asset('js/custom.js')}}"></script>
<script src="{{asset('js/axios.min.js')}}"></script>
<script src="{{asset('js/bootstrap.min.js')}}"></script>
<script src="{{asset('js/jquery-barcode.min.js')}}"></script>
<script src="{{asset('js/jquery-barcode.js')}}"></script>
<script src="{{asset('js/jquery-qrcode-0.18.0.min.js')}}"></script>
<script src="{{asset('js/jquery-qrcode-0.18.0.js')}}"></script>
<script src="{{asset('js/order.js')}}"></script>
<script src="{{asset('js/create.js')}}"></script>
<script src="{{asset('js/po.js')}}"></script>
<script src="{{asset('js/data-generate.js')}}"></script>

<script src="{{asset('js/BarcodeDownload.js')}}"></script>
<script src="{{asset('js/IncentoryLiveReports.js')}}"></script>
<script src="{{asset('js/goodsReceive.js')}}"></script>
<script src="{{asset('js/goodsIssue.js')}}"></script>
<script src="{{asset('js/BinCard.js')}}"></script>

@yield('script')
</body>
</html>

And in my blade I use the app.blade.php

@extends('Layout.app')
@section('content')
@endsection

In just any route containing single '/' jquery works. But if there is any parameter for the two or more '/' jquery doesn't load and work. In my console log all the jquery file throw error. See in image enter image description here

CodePudding user response:

Should be like that

add a slash of begin of src

<script src="/js/jquery-3.4.1.min.js"></script>

or just use asset() as you did with others.

  • Related