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
- Created a custom.js in my public folder with a simple function
- add script tag in my
app.blade.php
- 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
- Created a custom.js in my public folder with a simple function
- add script tag in my
app.blade.php
- 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
2 Answers
Reset to default 3- You misspelled javascript
- 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
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744233177a4564351.html
评论列表(0条)