Harjutuse lisamise-salvestamise näide: erinevus redaktsioonide vahel

Allikas: Lambda
Mine navigeerimisribale Mine otsikasti
Resümee puudub
Resümee puudub
1. rida: 1. rida:
 
<pre><nowiki>
  <html>
  <html>
   <head><title>Lisamine</title>
   <head><title>Lisamine</title>
89. rida: 89. rida:
   </body>
   </body>
  </html>
  </html>
</nowiki></pre>

Redaktsioon: 19. aprill 2012, kell 10:26

 <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 = "<tr><th>Name</th><th>Desc</th><th></th></tr>\n";
 
        for (i = 0; i < todolist.length; i++) {
          tablecontent += "<tr>\n<td>" + todolist[i].f0 + "</td><br/>\n";
          tablecontent += "<td>" + todolist[i].f1 + "</td>\n";
          tablecontent += "<td><a href=\"javascript:editTodo(" +
            todolist[i].id + ");\">Muuda</a></td>\n</tr>\n";
 
          tablecontent += "</tr>\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"><br/>
      <input id="todoname" type="text" placeholder="Title"><br/>
      <input id="tododesc" type="text" placeholder="Description"><br/>
      <input type="submit" value="Salvesta">
    </form>
 
    <div id="debug">
 
    </div>
 
    <table id="todolist">
    </table>
 
  </body>
 </html>