Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matthiasdebernardini/febf9dfa1630ea254f630f92749ef35f to your computer and use it in GitHub Desktop.
Save matthiasdebernardini/febf9dfa1630ea254f630f92749ef35f to your computer and use it in GitHub Desktop.
$(document).ready(function()
{
$.ajax({
//ajax request with paramaters to get a json file from the VU
url: 'https://wt.ops.labs.vu.nl/api18/f47cbdfe',
type: 'get',
dataType:'json',
success: function (response)
{
var trHTML = '';
$.each(response, function (key,value) {
trHTML +=
'<tr><td>' + value.brand +
'</td><td>' + value.model +
'</td><td>' + value.os +
'</td><td><img src="' + value.image +
'"></td><td>' + value.screensize +
'</td></tr>';
});
$('#myTable').append(trHTML);
}
});
$('form').submit(function(event) { //Trigger on form submit
$('#name + .throw_error').empty(); //Clear the messages first
$('#success').empty();
//Validate fields if required using jQuery
var postForm = $('form').serialize();
$.ajax({ //Process the form using $.ajax()
type : 'POST', //Method type
url : 'https://wt.ops.labs.vu.nl/api18/f47cbdfe',
//Your form processing file URL
data : postForm, //Forms name
dataType:"json",
success: function (response)
{
var trHTML = '';
$.each(response, function (key,value) {
trHTML +=
'<tr><td>' + value.brand +
'</td><td>' + value.model +
'</td><td>' + value.os +
'</td><td><img src="' + value.image +
'"></td><td>' + value.screensize +
'</td></tr>';
});
$('#myTable').append(trHTML);
}
});
event.preventDefault(); //Prevent the default submit
});
$("#reset").click(function(){
$.get("https://wt.ops.labs.vu.nl/api18/f47cbdfe/reset", function(){
alert("Your database is reset!");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment