can someone tell me how to make and call my own jquery functions? (im an absolute front end noob)
take this example code :-
<script>
$(document).ready(function(){
$.getJSON("http://127.0.0.1:8000/json/storylist/",
function(data){
$.each(data.stories, function(i,item){
$row = item.title;
$('#storylist tr:last').after("<tr><td>" + item.id + "</td><td>" + item.date + "</td><td>" + item.title + "</td><td></td><td>" + item.priority + "</tr>");
if ( i == 3 ) return false;
});
});
$("#refresh").click(function(event){
alert("yay u clicked refresh!");
$.getJSON("http://127.0.0.1:8000/json/storylist/",
function(data){
$.each(data.stories, function(i,item){
$row = item.title;
$('#storylist tr:last').after("<tr><td>" + item.id + "</td><td>" + item.date + "</td><td>" + item.title + "</td><td></td><td>" + item.priority + "</tr>");
if ( i == 3 ) return false;
});
});
});
});
</script>
you see the json call and code to edit the table is reproduced 2 times. my intention is for the json portion to run once when page is loaded, and each time when the user clicks the refresh link. if i go ahead with the current code, obviously it would be a major PITA in mantaining it.
Any clues?