Saved X
Google login
SignUp with Email
X

Jquery syntax for post request

theindreshverma ( Edited  Sep 01, 12:15 am )
Login

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.post demo</title>
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
 
<form action="/" id="searchForm">
  <input type="text" name="s" placeholder="Search...">
  <input type="submit" value="Search">
</form>
<div id="result"></div>
 
<script>
$( "#searchForm" ).submit(function( event ) {
  event.preventDefault();
  var $form = $( this ),
    term = $form.find( "input[name='s']" ).val(),
    url = $form.attr( "action" );

    var posting = $.post( url, { s: term } );

    posting.done(function( data ) {
       var content = $( data ).find( "#content" );
       $( "#result" ).empty().append( content );
     });
});
</script>
 
</body>
</html>

Sourcecode Tags

More Sourcecodes

More Sourcecodes