Created
January 21, 2018 18:16
-
-
Save matthiasdebernardini/febf9dfa1630ea254f630f92749ef35f to your computer and use it in GitHub Desktop.
This file contains 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
$(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