コードで何が問題なのか教えていただけますか? Javascript/JSONに慣れていないので、構文エラーだと思います。現在、このコードは何もしません。これは学校プロジェクトのためのものです。私のクラスは、フリータイム/クラスのスケジュールに基づいてアクティビティを予約するためのインターフェイスを提供することによって、ユーザーをつなぐアプリケーションを構築しています。ありがとう!JSONを使用してWebサービスからデータを取得する
<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#submit").click(function(){
var url = "http://3920project.azurewebsites.net/api/activity/";
//var email = "?email=" + getUrlVars();
//var title = "?title=" + "girls";
var title = "?title=" + getTitle();
//alert(url + title);
$.getJSON(url + title)
// data: {title: $("#title").val()
.done(function(res) {
//alert("done");
$.each(res, function(key, item) {
var colID = $('<td>', {
text: item.category
});
var colName = $('<td>', {
text: item.day + item.to + item.from
});
$('<tr>').append(colID, colName).appendTo($('#tblResult:last'));
}); //end of each()
}); //end of done()
}); //end of click()
}); //end of ready()
function getTitle() {
return document.getElementById('title').value;
}
</script>
<style type="text/css">
body {
font-family: arial;
}
th,
td {
margin: 0;
text-align: center;
border-collapse: collapse;
outline: 1px solid #e3e3e3;
}
td {
padding: 5px 10px;
}
th {
background: #666;
color: white;
padding: 5px 10px;
}
td:hover {
cursor: pointer;
background: #666;
color: white;
}
</style>
<title>Activity Search</title>
</head>
<body>
<div class="app">
Please enter activity:
<br></br>
<input type="text" id="title">
<input type="submit" id="submit" value="Search" />
<br></br>
</div>
<div>
<h2>Activity TimeTable</h2>
<table id="tblResult">
<tr>
<th>Activity</th>
<th>Category</th>
</tr>
</table>
</div>
</body>
</html>
jsエラーのchrome devツールで確認しましたか? – ItayB
あなたの 'res'を確認してください。それは文字列です。 'JSON.parse(res)'を使ってオブジェクトを作成する – Wainage
私のクラスメートは似たような仕事をしていて、JSON.parse(res)を使わず、彼女もうまくいきます。私は自分の問題が.click関数と関係していると考えています。なぜなら、彼女はユーザーからの入力を必要としないため、彼女とは異なる方法で行われる数少ない事の1つなのです。 – mikotochan