私はapi new york times検索エンジンを使用しています。私の質問は簡単です。私のHTMLの入力タイプテキストを使用してURLのパラメータを変更したいだけです。 どうすればいいですか? 終了日と並べ替えはパラメータの1つです。ちょうどhtmlの入力フィールドで文字列を変更する方法を知りたいだけです。入力文字列を使用してクエリ文字列にパラメータを追加する方法
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;
});
ありがとう、それは動作します! – CELB