how to show progress on ajax call


$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();

// Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with upload progress
console.log(percentComplete);
}
}, false);

// Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
// Do something with download progress
console.log(percentComplete);
}
}, false);

return xhr;
},
type: 'POST',
url: "/",
data: {},
success: function(data){
// Do something success-ish
}
});

BY LOVE
You need to call the progress bar class, That's IT

beforeSend: function ()
{
$('.loaderimg').show();
},
complete: function ()
{
$(".loaderimg").hide();
}

www.codegrepper.com
www.stackoverflow.com

how to show multiple image preview in jquery


<input id="file-input" type="file" multiple>
<div id="preview"></div>

function previewImages() {

var preview = document.querySelector('#preview');

if (this.files) {
[].forEach.call(this.files, readAndPreview);
}

function readAndPreview(file) {

// Make sure `file.name` matches our extensions criteria
if (!/.(jpe?g|png|gif)$/i.test(file.name)) {
return alert(file.name + " is not an image");
} // else...

var reader = new FileReader();

reader.addEventListener("load", function() {
var image = new Image();
image.height = 100;
image.title = file.name;
image.src = this.result;
preview.appendChild(image);
});

reader.readAsDataURL(file);

}

}

document.querySelector('#file-input').addEventListener("change", previewImages);

www.codegrepper.com
www.stackoverflow.com

how to show 1 day ago in javascript


function timeSince(date) {

var seconds = Math.floor((new Date() - date) / 1000);

var interval = seconds / 31536000;

if (interval > 1) {
return Math.floor(interval) + " years";
}
interval = seconds / 2592000;
if (interval > 1) {
return Math.floor(interval) + " months";
}
interval = seconds / 86400;
if (interval > 1) {
return Math.floor(interval) + " days";
}
interval = seconds / 3600;
if (interval > 1) {
return Math.floor(interval) + " hours";
}
interval = seconds / 60;
if (interval > 1) {
return Math.floor(interval) + " minutes";
}
return Math.floor(seconds) + " seconds";
}
var aDay = 24*60*60*1000;
console.log(timeSince(new Date(Date.now()-aDay)));
console.log(timeSince(new Date(Date.now()-aDay*2)));

www.codegrepper.com
www.stackoverflow.com

how to show a certain position in javascript


//How to print a specific element in javascript



/*====DESCRIPTION starts here=====
You can output a specific element or position of a list/array by
using the output statement which is console.log(). Within it, type in the
name of the array in which you are dealing with, and specify with brackets
after the array name, enter the number of the
position you want to output. Note though that as computers
count beginning from 0, you will have to subtract
1 from the original position we percieve.
====DESRCIPTION ends here=======*/

//====EXAMPLE 1 STARTS HERE=========
//Using an integer to output a specific element/position of an array.
//array named "arr" which consists of 4 elements which are integers.
var arr = [3,4,5,2]
console.log(arr[2]) //Outputs "5" because 5 is the second (or third) element of the array.
//====EXAMPLE 1 ENDS HERE=========

//====EXAMPLE 2 STARTS==========
//Using a variable to output a specific element/position of an array.
//array named "arr" which consists of 4 elements which are integers.
var arr = [8,9,3,5]
//A variable named "i" which stores a value of an integer, 2.
//Will be used to output the second element of the array.
var x = 0
console.log(arr[x]) //Outputs "8" since 8 is the 0 (or first) elemnt of the arary.
//====EXAMPLE 2 ENDS HERE==========

www.codegrepper.com
www.stackoverflow.com

how to show a success message when ajax called successfully


BY LOVE,
1- "beforeSend" event used to execute something before ajax call
2- "complete" event used to execute something after the ajax called successfull.

$.ajax({
url: ' @Url.Action("AttendanceUpdateLate", "Attendance")',
data: { Emp: $("#txtEmpid").val(), Status: $("#ddlAttendance").val(), day: $("#ddlday").val(), Month: $("#Month").val() },
datatype: "json",
type: "POST",
contenttype: 'application/json; charset=utf-8',
async: true,
success: function (data) {
alert(data);
},
beforeSend: function () {
alert("Alert showing before AJAX call");

},
complete: function () {
alert("Alert showing after AJAX call successfully");
$("#txtEmpid").val('');
$("#ddlday").val('');
$("#ddlAttendance").val('');
},
error: function (xhr) {
alert('error occured');
}
});

www.codegrepper.com
www.stackoverflow.com

how to show hide div in html javascript


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#myDIV {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: lightblue;
margin-top: 20px;
}
</style>
</head>
<body>

<p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p>

<button onclick="myFunction()">Try it</button>

<div id="myDIV">
This is my DIV element.
</div>

<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>

<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>

</body>
</html>

<button onclick="myFunction()">Click Me</button>

<div id="myDIV">
 
This is my DIV element.
</div>

function myFunction() {
  var x = document.getElementById("myDIV");

  if (x.style.display
=== "none") {
    x.style.display = "block";
  } else {
    x.style.display =
"none";
  }
}

www.codegrepper.com
www.stackoverflow.com