Browse Source

adding search query

master
rosh 4 years ago
parent
commit
9f5de526f3
  1. 4
      Login.html
  2. 43
      movies.js
  3. 2
      searchmovies.html

4
Login.html

@ -10,14 +10,14 @@
<body>
<div class ="login-page">
<div class="form">
<form class= "register-form" id="registerSubmit" onsubmit="submitForm(event, this)">
<form class= "register-form" id="registerSubmit" onsubmit="submitForm(event)">
<input type="text" placeholder="username" id="formName" required>
<input type="password" placeholder="password" id="formPassword" required>
<input type="text" placeholder="email id" id="formEmail" required>
<button type="submit">Create</button>
<p class="message">Already Registered? <a href="#">Login</a></p>
</form>
<form class="login-form" id="loginSubmit"onsubmit="submitForm1(event, this)">
<form class="login-form" id="loginSubmit"onsubmit="submitForm1(event)">
<input type ="text" placeholder="username" id="formName1" required>
<input type="password" placeholder="password" id="formPassword1" required>
<button type="submit">Login</button>

43
movies.js

@ -1,19 +1,25 @@
var searchkey;
$(document).ready(function(){
$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"},"slow");
})
});
async function submitForm(e, form){
$('.search-btn').click(function() {
searchkey= $('.search-movies').val();
});
});
async function submitForm(e){
e.preventDefault();
try {
const response = await fetch('https://mkr.thefeathers.in/register', {
method: 'post',
method: 'POST',
headers: new Headers({'content-type': 'application/json'}),
body: JSON.stringify({
"username": form.formName.value,
"email": form.formEmail.value,
"password": form.formPassword.value,
"username": document.getElementById('formName').value,
"email": document.getElementById('formEmail').value,
"password": document.getElementById('formPassword').value
})
});
const data = await response.json();
@ -28,13 +34,15 @@ async function submitForm(e, form){
}
}
var token;
async function submitForm1(e, form){
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
@ -43,6 +51,7 @@ async function submitForm1(e, form){
const data1 = await response.json();
//Success code goes here
alert(JSON.stringify(data1));
token = data1.token;
window.location = "searchmovies.html";
}
catch (err) {
@ -51,5 +60,25 @@ async function submitForm1(e, form){
}
}
async function search(e){
e.preventDefault();
try {
const response = await fetch('https://mkr.thefeathers.in/search/'+searchkey, {
method: 'GET',
headers: new Headers({'content-type': 'application/json'}),
headers: new Headers({ 'Authentication': token })
});
const data = await response.json();
//Success code goes here
//window.location = "searchmovies.html";
alert(JSON.stringify(data));
}
catch (err) {
//Failure
alert('Error');
}
}

2
searchmovies.html

@ -12,7 +12,7 @@
<form>
<div class="form-box">
<input type="text" class="search-movies" placeholder="Movies">
<button class="search-btn" type="button">Search</button>
<button class="search-btn" type="button" onclick="search(event)">Search</button>
</div>
</form>
</div>

Loading…
Cancel
Save