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 run mocha tests on asynchronous functions in script


// async/await
it('responds with matching records', async function() {
const users = await db.find({ type: 'User' });
users.should.have.length(3);
});

// promise.then()
it('should save without error', function(done) {
var user = new User('Luna');
user.save(function(err) {
if (err) done(err);
else done();
});
});

www.codegrepper.com
www.stackoverflow.com

how to run different node app on server different domains


var http = require('http'),
httpProxy = require('http-proxy');

var proxy_web = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8080
}
});

var proxy_api = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8081
}
});

http.createServer(function(req, res) {
if (req.headers.host === 'http://www.domain.com') {
proxy_web.proxyRequest(req, res);
proxy_web.on('error', function(err, req, res) {
if (err) console.log(err);
res.writeHead(500);
res.end('Oops, something went very wrong...');
});
} else if (req.headers.host === 'http://api.domain.com') {
proxy_api.proxyRequest(req, res);
proxy_api.on('error', function(err, req, res) {
if (err) console.log(err);
res.writeHead(500);
res.end('Oops, something went very wrong...');
});
}
}).listen(80);

www.codegrepper.com
www.stackoverflow.com

how to remove text style on td in angularjs


var colorSpan = element(by.css('span'));

it('should check ng-style', function() {
expect(colorSpan.getCssValue('color')).toMatch(/rgba(0, 0, 0, 1)|rgb(0, 0, 0)/);
element(by.css('input[value='set color']')).click();
expect(colorSpan.getCssValue('color')).toMatch(/rgba(255, 0, 0, 1)|rgb(255, 0, 0)/);
element(by.css('input[value=clear]')).click();
expect(colorSpan.getCssValue('color')).toMatch(/rgba(0, 0, 0, 1)|rgb(0, 0, 0)/);
});

span {
color: black;
}

<input type="button" value="set color" ng-click="myStyle={color:'red'}">
<input type="button" value="set background" ng-click="myStyle={'background-color':'blue'}">
<input type="button" value="clear" ng-click="myStyle={}">
<br/>
<span ng-style="myStyle">Sample Text</span>
<pre>myStyle={{myStyle}}</pre>

www.codegrepper.com
www.stackoverflow.com

how to remove horizontal scroll on elementor


(function (debug) {
var w = debug.documentElement.offsetWidth,
t = debug.createTreeWalker(debug.body, NodeFilter.SHOW_ELEMENT),
b;
while (t.nextNode()) {
b = t.currentNode.getBoundingClientRect();
if (b.right > w || b.left < 0) {
t.currentNode.style.setProperty('outline', '1px dotted red', 'important');
console.log(t.currentNode);
}
};
}(document));

www.codegrepper.com
www.stackoverflow.com

how to redirect to another page in javascript on submit type


<script type="text/javascript" language="javascript">
function redirect()
{
window.location.href="login.php";
}
</script>
<form name="form1" id="form1" method="post">
<input type="submit" class="button4" name="order"
id="order" value="Place Order" onclick="redirect();" >
</form>

www.codegrepper.com
www.stackoverflow.com

how to read if a person has send a message on discord.js


client.on('message', message => {
// this function can check whether the content of the message you pass is the same as this message
let filter = msg => {
return msg.content.toLowerCase() == message.content.toLowerCase() && // check if the content is the same (sort of)
msg.author == message.author; // check if the author is the same
}

message.channel.awaitMessages(filter, {
maxMatches: 1, // you only need that to happen once
time: 5 * 1000 // time is in milliseconds
}).then(collected => {
// this function will be called when a message matches you filter
}).catch(console.error);
});

www.codegrepper.com
www.stackoverflow.com