Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachEvents() {
- const kinveyAppId = "kid_rkKP5QGfe";
- const serviceUrl = "https://baas.kinvey.com/appdata/" + kinveyAppId;
- const kinveyUsername = "guest";
- const kinveyPassword = "guest";
- const base64auth = btoa(kinveyUsername + ":" + kinveyPassword);
- const authHeaders = {
- "Authorization": "Basic " + base64auth,
- "Content-type": "application/json"
- };
- $("#addButton").on('click', addCountry);
- $("#load").on('click', loadCountries);
- function addCountry() {
- console.log('check')
- let name = $("#addCountry").val();
- let obj = {
- name: name
- };
- let request = {
- method: "POST",
- url: serviceUrl + "/Country",
- data: JSON.stringify(obj),
- headers: authHeaders
- };
- $.ajax(request)
- .then(loadCountries)
- .catch(displayError);
- }
- function loadCountries() {
- let request = {
- method: "GET",
- url: serviceUrl + "/Country",
- headers: authHeaders
- };
- $.ajax(request)
- .then(displayCountries)
- .catch(displayError)
- }
- function displayCountries(data) {
- for(let country of data){
- let id = country._id;
- let tr = $("<tr>").attr('data-id', id);
- let nameTd = $("<td>").text(country.name).appendTo($(tr));
- let actionsTd = $("<td>");
- let editBut = $("<input type='button' id='editBut' value='Edit'>").appendTo($(actionsTd));
- let deleteBut = $("<input type='button' id='deleteBut' value='Delete'/>").appendTo($(actionsTd));
- $(actionsTd).appendTo($(tr));
- $(tr).appendTo($("#countries"));
- }
- }
- $("#deleteBut").click(deleteCountry);
- function deleteCountry() {
- console.log(5)
- }
- function displayError(error){
- console.log(error.statusText);
- }
- }
Add Comment
Please, Sign In to add comment