สอบถามวิธี loading request Jquery ครับ ให้ขึ้น loading ก่อนแสดงผล
โค้ดทั้งหมดแบบนี้นะครับ
Code (PHP)
<script type="text/javascript">
function searchSubject()
{
$.post("result_sub.php",{
mySearch: $("#txtSearch").val()},
function(msg){
$("#myResult").html(msg);
}
);
}
</script>
<label for="txtSearch">ค้นหาจากรหัสวิชาหรือชื่อวิชา : </label>
<input type="text" name="txtSearch" id="txtSearch" />
<input type="button" name="btn_search" id="btn_search" value="ค้นหา" onclick="javascript:searchSubject();" />
</div>
<div class="cleaner_h5"></div>
<div id="loading" align="center"></div>
<span id="myResult"></span>
Date :
2014-09-19 16:02:24
By :
angelkiller9
Code (JavaScript)
function searchSubject(){
$.ajax({
url: 'result_sub.php',
data: {mySearch: $("#txtSearch").val()},
type: 'post',
success: function (response) {
$("#myResult").html(response);
}
}).ajaxStart(function() {
/* Stuff to do when an AJAX call is started and no other AJAX calls are in progress */;
}).ajaxStop(function() {
/* stuff to do when all AJAX calls have completed */;
});
}
Date :
2014-09-19 20:18:44
By :
Krungsri
Code (PHP)
<div align="center">
<label for="txtSearch">ค้นหาจากรหัสวิชาหรือชื่อวิชา : </label>
<input type="text" name="txtSearch" id="txtSearch" />
<input type="button" name="btn_search" id="btn_search" value="ค้นหา" onclick="javascript:searchSubject();" />
</div>
<div class="cleaner_h5"></div>
<div id="loading2" align="center"></div>
<span id="myResult"></span>
Code (JavaScript)
$(document).ready(function() {
$('#btn_search').click(function(event) {
var keyWord = $("#txtSearch").val();
if(keyWord!=""){
$.ajax({
url:'result_sub.php',
data:{ mySearch:keyWord },
type:'post',
success:function(msg){
$("#myResult").html(msg);
}
});
}
});
}).ajaxStart(function(){
$("#loading2").html('<div align="center"><img src="img/loading2.gif"></div>');
}).ajaxStop(function(){
$("#loading2").hide();
});
Date :
2014-09-22 15:34:29
By :
Krungsri
Load balance : Server 05