Created
April 7, 2014 09:42
-
-
Save bjorn-ali-goransson/10017375 to your computer and use it in GitHub Desktop.
Template for REST demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(message: String) | |
@main("Welcome to Play") { | |
<ul id="students"></ul> | |
<hr> | |
<button id="create-new-student">Create new</button> | |
<script> | |
function loadListOfStudents(){ | |
$('#students').empty(); | |
$.get('/students', function(students){ | |
$.each(students, function(arrayIndex, student){ | |
$('<li>') | |
.append(student.surname) | |
.append(', ') | |
.append(student.name) | |
.append(' (') | |
.append(student.id) | |
.append(')') | |
.append(' ') | |
.append( | |
$('<button>') | |
.text('GET') | |
.click(function(){ | |
location.href = "/students/" + student.id; | |
}) | |
) | |
.append(' ') | |
.append( | |
$('<button>') | |
.text('Delete') | |
.click(function(){ | |
$.ajax({ | |
url: '/students/' + student.id, | |
type: 'DELETE' | |
}) | |
.always(function(){ | |
loadListOfStudents(); | |
}); | |
}) | |
) | |
.append(' ') | |
.append( | |
$('<button>') | |
.text('Update') | |
.click(function(){ | |
$.ajax({ | |
url: '/students/' + student.id, | |
type: 'PUT', | |
data: { | |
name: prompt("Student name please?", student.name), | |
surname: prompt("Student surname please?", student.surname) | |
} | |
}) | |
.always(loadListOfStudents); | |
}) | |
) | |
.appendTo('#students'); | |
}); | |
}); | |
} | |
$(loadListOfStudents); | |
$('#create-new-student').click(function(){ | |
$.ajax({ | |
url: '/students', | |
type: 'PUT', | |
data: { | |
name: prompt("Student name please?"), | |
surname: prompt("Student surname please?") | |
} | |
}) | |
.always(loadListOfStudents); | |
}); | |
</script> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment