Created
October 4, 2018 10:38
-
-
Save chanchal-357/28e31302af94812809dc24f66e326adc to your computer and use it in GitHub Desktop.
Jquery Async using Promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> Thai Text only </title> | |
</head> | |
<link href="style.css" rel="stylesheet" type="text/css" /> | |
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$('.thai').on('input', function (event) { | |
this.value = this.value.replace(/[^\u0E00-\u0E7F0-9]/g, ''); | |
}); | |
}); | |
function asyncFun() { | |
asyncfunction().then(function(result){ | |
alert(result); | |
}, | |
function(err){ | |
console.log('This is error message.'); | |
}); | |
// Code independent of result | |
alert('The End'); | |
} | |
function asyncfunction() { | |
var dfrd1= $.Deferred(); | |
setTimeout(function() { | |
var result = 'Hello asynchronous world!'; | |
$("#func").val(result); | |
dfrd1.resolve(result); | |
}, 1000); | |
return dfrd1.promise();; | |
} | |
</script> | |
<body> | |
<input type="text" class="thai" /> | |
<input type="text" value="" id="func"/> | |
<div id="banner-message"> | |
<button onclick="asyncFun();">Async Call</button> | |
</div> | |
</body> | |
</html | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: #20262E; | |
padding: 20px; | |
font-family: Helvetica; | |
} | |
#banner-message { | |
background: #fff; | |
border-radius: 4px; | |
padding: 20px; | |
font-size: 25px; | |
text-align: center; | |
transition: all 0.2s; | |
margin: 0 auto; | |
width: 300px; | |
} | |
button { | |
background: #0084ff; | |
border: none; | |
border-radius: 5px; | |
padding: 8px 14px; | |
font-size: 15px; | |
color: #fff; | |
} | |
#banner-message.alt { | |
background: #0084ff; | |
color: #fff; | |
margin-top: 40px; | |
width: 200px; | |
} | |
#banner-message.alt button { | |
background: #fff; | |
color: #000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment