最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How Can I add Custom javascript file in my laravel project? - Stack Overflow

programmeradmin4浏览0评论

Can anyone please guide me regarding how can I add custom javascript in Laravel project?

I did google and found some steps but unable to figure out what the error is going on?

Steps I

  1. Created a custom.js in my public folder with a simple function
  2. add script tag in my app.blade.php
  3. extends my layout

But the function is not working

$(document).ready(function()
{
    alert("hello this is test");
})

custom.js

enter code here

<script type="text/javascrip" src=".4.1/jquery.min.js"></script>"
<script type="text/javascript" src="{{asset('js/custom.js')}}"></script>

code I added in my main file app.blade

but when load my page it doesn't give me an alert. Alert is just for testing I tried with various function.

Can anyone please guide me regarding how can I add custom javascript in Laravel project?

I did google and found some steps but unable to figure out what the error is going on?

Steps I

  1. Created a custom.js in my public folder with a simple function
  2. add script tag in my app.blade.php
  3. extends my layout

But the function is not working

$(document).ready(function()
{
    alert("hello this is test");
})

custom.js

enter code here

<script type="text/javascrip" src="https://ajax.googleapis./ajax/libs/jquery/3.4.1/jquery.min.js"></script>"
<script type="text/javascript" src="{{asset('js/custom.js')}}"></script>

code I added in my main file app.blade

but when load my page it doesn't give me an alert. Alert is just for testing I tried with various function.

Share Improve this question edited Sep 24, 2019 at 11:16 Udhav Sarvaiya 10.1k13 gold badges60 silver badges67 bronze badges asked Sep 24, 2019 at 10:39 Samir ParuthiSamir Paruthi 1211 gold badge3 silver badges14 bronze badges 4
  • Have you tried viewing the source code from the web browser? – Chuksy Commented Sep 24, 2019 at 10:41
  • First of all thanks chusky for showing interest but yes I did and its showing but nothing working and one more thing If I am making a simple function without $document.ready like function check(){alert("example") and call it via on click function its working but when i use it by $(document).ready(function(){}) its not working – Samir Paruthi Commented Sep 24, 2019 at 10:43
  • 1 @SamirParuthi Hello, Can you check your browser console? If any error occurred. please shared with us. – Amit Senjaliya Commented Sep 24, 2019 at 10:48
  • What error are you getting? – Dilip Hirapara Commented Sep 24, 2019 at 10:52
Add a ment  | 

2 Answers 2

Reset to default 3
  1. You misspelled javascript
  2. Remove the (") after writing the </script>

For Javascript:

<script src="https://ajax.googleapis./ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="{{ URL::asset('js/custom.js') }}"></script>

Make your directory structure is like this for JS: /public/js/custom.js

I have to review your code. I have found an error in your code like a spelling mistake.

<script type="text/javascript" 
 src="https://ajax.googleapis./ajax/libs/jquery/3.4.1/jquery.min.js"></script>"

You have miss t at the end of javascript.

发布评论

评论列表(0)

  1. 暂无评论