I work with the api new york times search engine, my question is simple, i just want to change parameters in my url using a input type text in my html. How can i do that ? End date and sort are one of the parameter, i just want to know how can i change the string with an input field in html. here a copy of my code :
html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel='stylesheet' type="text/css" href="nyt.css">
<link rel='stylesheet' type="text/css" href="font.css">
<link rel='stylesheet' type="text/css" href="grille.css">
</head>
<body>
<div class='container'>
<button type="submit" id='searchButton'></button>
<input type="text" id='searchTerm' placeholder="search">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src='nyt.js'></script>
</body>
</html>
js :
var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json";
var searchTerm = document.getElementById('searchButton');
url += '?' + $.param({
'api-key': "[API KEY]",
'end_date': "19440606",
'sort': "newest"
});
$.ajax({
url: url,
method: 'GET',
q: searchTerm,
}).done(function(result) {
console.log(result);
}).fail(function(err) {
throw err;
});