perfettiful
4/11/2018 - 11:07 PM

jQuery AJAX

jQuery AJAX

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript">
    // The below code fills in the first row of the table
    var movie = "Mr. Nobody";
    var queryURL = "https://www.omdbapi.com/?t=" + movie + "&y=&plot=short&apikey=trilogy";

    $.ajax({
      url: queryURL,
      method: "GET"
    }).then(function(response) {

      // Obtain a reference to the tbody element in the DOM
      var tableRow = $("tbody");
      // Create and save a reference to new empty table row
      
      

      var title = "<td>" + response.Title + "</td>";
      var year = "<td>" + response.Year + "</td>";
      var actors = "<td>" + response.Actors + "</td>";
      // Create and save references to 3 td elements containing the Title, Year, and Actors from the AJAX response object
      // Append the td elements to the new table row
      tableRow.append(title, year, actors);
      // Append the table row to the tbody element
    });