Answers for "ajax post rest api example"


ajax post rest api example

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title> demo</title>
  <script src=""></script>
<form action="/" id="searchForm">
  <input type="text" name="s" placeholder="Search...">
  <input type="submit" value="Search">
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
// Attach a submit handler to the form
$( "#searchForm" ).submit(function( event ) {
  // Stop form from submitting normally
  // Get some values from elements on the page:
  var $form = $( this ),
    term = $form.find( "input[name='s']" ).val(),
    url = $form.attr( "action" );
  // Send the data using post
  var posting = $.post( url, { s: term } );
  // Put the results in a div
  posting.done(function( data ) {
    var content = $( data ).find( "#content" );
    $( "#result" ).empty().append( content );
Posted by: Guest on February-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language