Skip to content

Instantly share code, notes, and snippets.

@bendo01
Created June 20, 2021 08:20
Show Gist options
  • Save bendo01/9266085d60560cb9d60fd9d135866d9b to your computer and use it in GitHub Desktop.
Save bendo01/9266085d60560cb9d60fd9d135866d9b to your computer and use it in GitHub Desktop.
Axios Example Laravel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<title>TODO APP</title>
</head>
<body>
</body>
<script async src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
// login
/*
axios.post('http://todo.test/api/login', {
email: 'bendo01@gmail.com',
password: 'sayatest'
}, {
strictSSL: false,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
*/
// get data list
/*
axios({
url: 'http://todo.test/api/todos',
method: 'get',
headers: { Authorization: 'Bearer 10|rU4KB3bCvbzn3nkgxrPd3plUaVrbA39TSzCxnvdY' }
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
*/
/*
axios({
url: 'http://todo.test/api/todos/67cc1454-1d45-47ce-af60-5a54ec9cab05',
method: 'get',
headers: { Authorization: 'Bearer 10|rU4KB3bCvbzn3nkgxrPd3plUaVrbA39TSzCxnvdY' }
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
*/
/*
axios({
url: 'http://todo.test/api/todos/67cc1454-1d45-47ce-af60-5a54ec9cab05',
method: 'post',
headers: { Authorization: 'Bearer 10|rU4KB3bCvbzn3nkgxrPd3plUaVrbA39TSzCxnvdY' },
data: {
description: 'Saya Mau MAkan',
is_finish: false,
_method:'put'
},
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
*/
// menyimpan data
/*
axios({
url: 'http://todo.test/api/todos',
method: 'post',
headers: { Authorization: 'Bearer 10|rU4KB3bCvbzn3nkgxrPd3plUaVrbA39TSzCxnvdY' },
data: {
description: 'Saya Masjidil Agsha',
is_finish: false
},
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
*/
axios({
url: 'http://todo.test/api/todos/67cc1454-1d45-47ce-af60-5a54ec9cab05',
method: 'post',
headers: { Authorization: 'Bearer 10|rU4KB3bCvbzn3nkgxrPd3plUaVrbA39TSzCxnvdY' },
data: {
_method:'delete'
},
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment