vendredi 4 janvier 2019

How can I use jQuery in Laravel?

After reading this question and removing the defer from the <script> tag. I still receive this error:

Uncaught ReferenceError: jQuery is not defined

I read that app.js in laravel already includes jQuery. This is defined in my layout which looks like this:

<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="">

    <title> | Regression Platform</title>

    <!-- Scripts -->
    <script src=""></script>

However, when I try to then utilise jQuery in a view (after requiring the layout) like so:

@extends('layouts.app')
@section('content')

<script>
    jQuery(document).ready(function(){
        $('.saved-ai').click(function() {
            $('#ainame').val(this.html());
        });
    });
</script>

I get the error. I have tried using $(document).ready(function() {}) instead but I receive $ is not defined. I also tried to then include jQuery manually. This worked fine, up until I tried to use this.html() which threw me errors that .html() did not exist in app.js.

How can I use jQuery in Laravel?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2F8al9i
via IFTTT

Aucun commentaire:

Enregistrer un commentaire