Jquery
<script src="http://localhost/project/public/plugins/jQuery/jquery-2.2.3.min.js"></script>
my code
<script type="text/javascript">
function readURL(input){
if(input.files && input.files[0]){
var reader = new FileReader();
reader.onload=function(e){
$('#showimages').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#inputimages").change(function(){
readURL(this);
});
</script>
<img src="" id="showimages">
<input type="file" name="images" id="inputimages">
and i got this error
Uncaught ReferenceError: $ is not defined at http://localhost/project/public/user/1/edit:308:9
*line 308 -> $("#inputimages").change(function(){
Im new in js and jquery, Help me solve this error please...
I wrote the script out of the section. That was why the error occurred, see my answer.
Thankyou for everyone!
This error is solved, in .blade.php laravel i have to write
@section('script')
<script type="text/javascript">
//my code here
</script>
@endsection
To use Jquery, remember it has to import before using
Your problem is look like your Jquery is not imported. Maybe your path is incorrect or you imported it after your script.
First, check this url http://localhost/project/public/plugins/jQuery/jquery-2.2.3.min.js with with your web browser. If it exist you will see a lot of javascript code there.
Then to import it from your local server.
<script src="http://localhost/project/public/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script>
//your script here.
</script>
Another choice using cdn instead:
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script>
//your script here
</script>
Looks like jQuery wasn't loaded when your script is exectued.
You should load jQuery before scripts that are using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With