$(document).ready(function(){ $('.message a').click(function(){ $('form').animate({height: "toggle", opacity: "toggle"},"slow"); }); }); async function submitForm(e){ e.preventDefault(); try { const response = await fetch('https://mkr.thefeathers.in/register', { method: 'POST', headers: new Headers({'content-type': 'application/json'}), body: JSON.stringify({ "username": document.getElementById('formName').value, "email": document.getElementById('formEmail').value, "password": document.getElementById('formPassword').value }) }); const data = await response.json(); //Success code goes here //window.location = "searchmovies.html"; alert(JSON.stringify(data)); $('form').animate({ height: "toggle", opacity: "toggle" }, "slow"); } catch (err) { //Failure alert('Error'); } } async function submitForm1(e){ e.preventDefault(); try { const response = await fetch('https://mkr.thefeathers.in/login', { method: 'POST', headers: new Headers({'content-type': 'application/json'}), body: JSON.stringify({ "username" : document.getElementById('formName1').value, "password" : document.getElementById('formPassword1').value }) }); const data1 = await response.json(); //Success code goes here alert(JSON.stringify(data1)); window.localStorage.setItem('Token', (data1.token)); window.location = "searchmovies.html"; } catch (err) { //Failure alert('Error'); } } async function search(e){ e.preventDefault(); var searchkey= $('.search-movies').val(); var Token=window.localStorage.getItem('Token'); try { const response = await fetch('https://mkr.thefeathers.in/search/'+searchkey, { method: 'GET', headers: new Headers({'content-type': 'application/json', 'Authentication': Token }), }); const data2 = await response.json(); //Success code goes here //window.location = "searchmovies.html"; alert(JSON.stringify(data2)); var results =data2.results; if(!results) return; var listItems = results.map(myfunction); window.localStorage.setItem('movieID', (results.movieID)); var movieID=window.localStorage.getItem('movieID'); function myfunction(results){ var x = document.createElement("li"); var a = document.createElement("a"); var t = document.createTextNode(results.title); x.appendChild(a); a.appendChild(t); a.setAttribute("href","https://mkr.thefeathers.in/movie/"+movieID); x.setAttribute("class","list"); return x; } document.getElementById("slideContainer").append(...listItems); $('.list').click(function(event){ moviePage(event); }); } catch (err) { //Failure alert('Error'); } } async function moviePage(e){ e.preventDefault(); var Token=window.localStorage.getItem('Token'); var movieID=window.localStorage.getItem('movieID'); window.location = "searchmovies.html"; try { const response = await fetch('https://mkr.thefeathers.in/movie/'+movieID, { method: 'GET', headers: new Headers({'content-type': 'application/json', 'Authentication': Token }), }); const data3 = await response.json(); //Success code goes here alert(JSON.stringify(data3)); var results1 =data2.results; window.location = "moviesPage.html"; document.getElementById("Container").append(results1.movieID); document.getElementById("Container").append(results1.title); document.getElementById("Container").append(results1.overview); document.getElementById("Container").append(results1.poster); document.getElementById("Container").append(results1.release); document.getElementById("Container").append(results1.watchStatus); document.getElementById("Container").append(results1.rating); } catch (err) { //Failure alert('Error'); } }