Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the code popup.js given below: document.addEventListener('DOMContentLoaded', function() { document.getElementById('searchButton').addEventListener('click', search); }); function search() { var searchTerm = document.getElementById('searchTerm').value; var query = {'searchTerm': searchTerm}; chrome.tabs.query({active:

Consider the code popup.js given below:

document.addEventListener('DOMContentLoaded', function() {

document.getElementById('searchButton').addEventListener('click', search);

});

function search() {

var searchTerm = document.getElementById('searchTerm').value;

var query = {'searchTerm': searchTerm};

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {

var url = tabs[0].url;

var xhr = new XMLHttpRequest();

xhr.open('POST', 'http://localhost:8080/search');

xhr.setRequestHeader('Content-Type', 'application/json');

xhr.onload = function() {

if (xhr.status === 200) {

displayResults(xhr.responseText);

} else {

alert('Error: ' + xhr.statusText);

}

};

xhr.send(JSON.stringify(query));

});

}

function displayResults(results) {

var div = document.getElementById('results');

div.innerHTML = '';

var ul = document.createElement('ul');

JSON.parse(results).forEach(function(result) {

var li = document.createElement('li');

li.textContent = result;

ul.appendChild(li);

});

div.appendChild(ul);

}

Here JavaScript code is responsible for handling the user input, making the AJAX request to the REST API or Servlet, and displaying the search results of a word from a web page.

Question:

how can REST api be coded in order to be called using the url http://localhost:8080/search , explain about the rest api how it coded and called

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+Where do you want to live and work?

Answered: 1 week ago

Question

=+1 Where are the best places in the world to live (and work)?

Answered: 1 week ago