lundi 27 février 2017

Uncaught Referrence error

I am using laravel 5.3. I am trying to validate form data with jquery validate plugin. After data validation i want to fire an ajax call. Here is my code

<!doctype html>
<html>
<head>
    <meta name="_token" content="{!! csrf_token() !!}"/>
    <script src="http://ift.tt/1dLCJcb"></script>
    <script src="http://ift.tt/1NKbGQl"></script>
    <link href="http://ift.tt/1jAc5cP" rel="stylesheet" type="text/css" />
    <script src="http://ift.tt/1jAc4pg"></script>
    <script src="/js/bootstrap-tagging.js"></script>
    <link type="text/css" href="/css/bootstrap-tagging.css" rel="stylesheet">
    <script src="/js/tapered.bundle.js"></script>
    <script src="http://ift.tt/2iFPHiv"></script>
    <script src="/js/validation.js"></script>
    <script>
        $(document).ready(function() {
            function ajaxCall() {
                console.log("event occured");
                $.ajax({
                    type: "POST",
                    url: '/storeproject',
                    data: { _token: "" },
                    success: function( msg ) {
                        console.log(msg);
                    }
                });
            }
        });
    </script>
</head>
<body>
<form role="form" method="POST" action="javascript:ajaxCall()" id="test-form">
    {!! csrf_field() !!}
    <label>Project Name</label>
    <input class="form-control" id="projectName" placeholder="Name" name="projectname" type="text" autofocus="">
    <input type="submit"  id="submit" name="submit" class="btn btn-primary" value="Add">
</form>
</body>
</html>

When i hit the add button gives me the error

VM681:1 Uncaught ReferenceError: ajaxCall is not defined at :1:1

but if I avoid the document ready function it works fine. What is the problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire