不推荐使用的Ajax或JQuery命令导致没有结果返回 [英] Deprecated Ajax Or JQuery Command Cause No Result Returned
问题描述
<script type="text/javascript">
$(document).ready(function(){
function loading_show(){
$('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}
function loadData(page){
loading_show();
$.ajax
({
type: "POST",
url: "load_data.php",
data: "page="+page,
success: function(msg){
$("#container").ajaxComplete(function(event, request, settings)//.ajaxComplete is good
{
loading_hide();
$("#container").html(msg);
});
}
});
alert();
}
loadData(1); // For first time page load default results
$('#container .pagination li.active').on('click',function(){//replaced .live with .on
var page = $(this).attr('p');
loadData(page);
});
$('#go_btn').on('click',function(){//replaced .live with .on
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});
</script>
上面是此处的分页教程中的分页代码. 我尝试使用jquery 1.9.1而不是代码段使用1.4. 但似乎即使我将已弃用的.live更改为.on,仍然没有任何结果.我在这段代码中找不到任何不推荐使用的代码.但是,本教程中的其他代码似乎也很完美.因此,我认为javascript&上面的ajax代码.
Above is the pagination code from The paginatio tutorial here. I try to use jquery 1.9.1 instead of the code piece use 1.4. But seem even I changed the deprecated .live to .on, still, no result has been rendered. I can not find any deprecated code among this piece. However, other code in the tutorial are seemingly perfect as well. So I would consider there must be some thing wrong with the javascript & ajax code above.
在KyleK的帮助下,修改后的版本(至今仍无法使用)
with the help from KyleK, the modified version (yet still not working) is below
<script type="text/javascript">
$(document).ready(function(){
function loading_show(){
$('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}
function loadData(page){
loading_show();
$.ajax
({
type: "POST",
url: "load_data.php",
data: {page: page},
//ORIGINAL data: "page="+page,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
loadData(1); // For first time page load default results
$('body').on('click','#container .pagination li.active', function(){
//ORIGINAL $('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});
$('body').on('click','#go_btn',function(){
//ORIGINAL $('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});
</script>
推荐答案
更改在ajax中传递数据的方式...
Change the way your data is passed in the ajax...
来自...
url: "load_data.php",
data: "page="+page,
收件人..
url: "load_data.php",
data: {page: page},
并更改此...
$('#container .pagination li.active').on('click',function(){
对此...
$('body').on('click','#container .pagination li.active', function(){
这里也是...
$('#go_btn').on('click',function()
致...
$('body').on('click','#go_btn',function()
我想我已经建议昨天我上次回答同样的问题...
I think I already suggested that the last time I answered this same question yesterday...
这篇关于不推荐使用的Ajax或JQuery命令导致没有结果返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!