Browse Source

search as list

master
rosh 4 years ago
parent
commit
f43406a9e0
  1. 22
      movies.js
  2. 1
      searchmovies.html

22
movies.js

@ -34,7 +34,6 @@ async function submitForm(e){
} }
} }
var token;
async function submitForm1(e){ async function submitForm1(e){
e.preventDefault(); e.preventDefault();
@ -51,7 +50,7 @@ async function submitForm1(e){
const data1 = await response.json(); const data1 = await response.json();
//Success code goes here //Success code goes here
alert(JSON.stringify(data1)); alert(JSON.stringify(data1));
token = data1.token; window.localStorage.setItem('Token', (data1.token));
window.location = "searchmovies.html"; window.location = "searchmovies.html";
} }
catch (err) { catch (err) {
@ -62,17 +61,26 @@ async function submitForm1(e){
async function search(e){ async function search(e){
e.preventDefault(); e.preventDefault();
var Token=window.localStorage.getItem('Token');
try { try {
const response = await fetch('https://mkr.thefeathers.in/search/'+searchkey, { const response = await fetch('https://mkr.thefeathers.in/search/'+searchkey, {
method: 'GET', method: 'GET',
headers: new Headers({'content-type': 'application/json'}), headers: new Headers({'content-type': 'application/json', 'Authentication': Token }),
headers: new Headers({ 'Authentication': token })
}); });
const data = await response.json(); const data2 = await response.json();
//Success code goes here //Success code goes here
//window.location = "searchmovies.html"; //window.location = "searchmovies.html";
alert(JSON.stringify(data)); alert(JSON.stringify(data2));
var str = '<ul>'
var result = data2.results;
result.forEach(myfunction);
function myfunction(slide){
str += '<li>'+ slide + '</li>';
}
str += '</ul>';
document.getElementById("slideContainer").innerHTML = str;
} }
catch (err) { catch (err) {
//Failure //Failure

1
searchmovies.html

@ -15,6 +15,7 @@
<button class="search-btn" type="button" onclick="search(event)">Search</button> <button class="search-btn" type="button" onclick="search(event)">Search</button>
</div> </div>
</form> </form>
<div id="slideContainer"></div>
</div> </div>
<div id="output"></div> <div id="output"></div>
</body> </body>
Loading…
Cancel
Save