Hello, I am trying to improve the processing of a form with text using jquery. The script displays successfully saved data from the form to the screen without reloading the page if they have been tested for the number of sent characters. The project is done on the Laravel 5.3 php framework.
What exactly are I trying to do? When displaying data, the text should be displayed in green, should appear smoothly, and after 2-3 seconds change to black.
With the output of the text in green, everything is fine, but the animation does not work out. Tell me how you can organize it. Thanks in advance.
Such code at the moment:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .center { text-align: center; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function () { $("#sendForm").submit(function (ev) { ev.preventDefault(); $('#messageShow').hide(); var title = $("#title").val(); var fail=""; if (title.length < 3) fail="ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΡΠΎΡΡΠΎΡΡΡ ΠΈΠ· Π½Π΅ ΠΌΠ΅Π½Π΅Π΅ 3 ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ²"; if (fail!=""){ $('#messageShow').css({'color' : 'red'}); $('#messageShow').html(fail); $('#messageShow').show(); return false; } $.ajax({ url: '{{action('CategoriesController@store')}}', type:'POST', data:$('#sendForm').serialize(), cache:false, success: function () { var neww = "new!"; $("#title").val(""); $("#new").css({'color':'red'}); $("#new").html(neww); $("#categoryBlock").append("<h4>"+title+"</h4>").css({'color' : 'limegreen'}).show(); } }) }) }) </script> </head> <body> <div class="center"> <form method="POST" enctype="multipart/form-data" id="sendForm" action="{{action('CategoriesController@store')}}"> {{ csrf_field() }} <input type="text" name="title" id="title" placeholder="ΠΠΎΠ±Π°Π²ΠΈΡΡ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡ"> <input type="submit" class="btn-primary" value="ΠΠΎΠ±Π°Π²ΠΈΡΡ" > <div id="messageShow"></div> </form> @if(Session::has('message')) {{Session::get('message')}} @endif </div> <br> <div class="center"> <h3>Π‘ΠΏΠΈΡΠΎΠΊ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ:</h3><br> @foreach($categories as $category) <h4>{{$category->title}}</h4> @endforeach <div id="new"></div> <div id="categoryBlock"></div> </div> </body> </html> @endsection
$('.myclass').css('color','green')- Abmin