Native methods for replace frontend frameworks.
$.getJSON('/my/url', function(data) {
});
fetch('/my/url')
.then(response => response.json())
.then(data => console.log(data)); // Do something.
$.ajax({
type: 'GET',
url: '/my/url',
success: function(resp) {
},
error: function() {
}
});
fetch('/my/url')
.then(data => console.log(data)) // Success
.catch(error => console.log(error)); // Error
$.ajax({
type: 'POST',
url: '/my/url',
data: data
});
fetch('/my/url', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
data: data, // Data
});
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
html {
scroll-behavior: smooth;
}
This trick is used in this website.
<table class="table">
...
</table>
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
th, td {
text-align: left;
padding: 16px;
border-bottom: 1px solid #ddd;
}
<table class="table table-striped">
...
</table>
tr:nth-child(even) {
background-color: #f2f2f2;
}
<div class="table-responsive">
<table class="table">
...
</table>
</div>
<div style="overflow-x:auto;">
<table>
...
</table>
</div>