Harjutuse lisamise-salvestamise näide
<html>
<head><title>Lisamine</title>
</head>
<body>
<script src="jquery.js" type="text/javascript">
</script>
<script type="text/javascript">
function editTodo (index) {
$("#debug").html(index);
}
function renderTodoCallback( todolist, textStatus, jqXHR) {
$("#debug").html("");
var tablecontent = "NameDesc\n";
for (i = 0; i < todolist.length; i++) {
tablecontent += "\n" + todolist[i].f0 + "
\n";
tablecontent += "" + todolist[i].f1 + "\n";
tablecontent += "<a href=\"javascript:editTodo(" +
todolist[i].id + ");\">Muuda</a>\n\n";
tablecontent += "\n";
}
$("#todolist").html(tablecontent);
}
function renderTodo() {
$.getJSON("http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui3/otsi.py?table=t0&salvestaja=test@example.ee", renderTodoCallback);
}
function addTodoCallback(sendstatus, textStatus, jqXHR) {
if (sendstatus == 0) {
$("#debug").html("Error with saving entry. Sorry about that.");
return;
}
renderTodo();
}
function addTodo() {
/* add checking */
var url="http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui3/salvesta.py?table=t0&";
url += "salvestaja=" + $("#salvestaja").val();
url += "&f0=" + $("#todoname").val();
url += "&f1=" + $("#tododesc").val();
$("#debug").html(url);
$.getJSON(url, addTodoCallback );
return false /* don't send the form using normal means */
}
$(document).ready( function() {
renderTodo();
});
</script>
<form onsubmit="return addTodo();">
<input id="salvestaja" type="text" placeholder="Salvestaja" value="test@example.ee">
<input id="todoname" type="text" placeholder="Title">
<input id="tododesc" type="text" placeholder="Description">
<input type="submit" value="Salvesta">
</form>
</body> </html>