Php 使用Jquery AJAX后mootools AJAX出现问题
我有一个关于Mootools中Ajax调用的小问题。 我使用AJAX在Jquery中编写了一个处理程序脚本和一个侦听器脚本,但我不知道如何将其转换为mootools而不是AJAX 使用带有onclick='changePage($page,$total')的html链接标记调用该函数 这是最初的jqueryajax调用。它在Ajax文件中作为数组返回。 返回的变量如下所示:Php 使用Jquery AJAX后mootools AJAX出现问题,php,jquery,ajax,mootools,Php,Jquery,Ajax,Mootools,我有一个关于Mootools中Ajax调用的小问题。 我使用AJAX在Jquery中编写了一个处理程序脚本和一个侦听器脚本,但我不知道如何将其转换为mootools而不是AJAX 使用带有onclick='changePage($page,$total')的html链接标记调用该函数 这是最初的jqueryajax调用。它在Ajax文件中作为数组返回。 返回的变量如下所示: $data = array(); $data['result'] = '1'; $data['html'] = $this
$data = array();
$data['result'] = '1';
$data['html'] = $this->result; //Returns Pagination bar with current selected page.
$data['html2'] = $this->result2; //Returns a block of HTML (result of Solr request styled with bootstrap
脚本的JQuery版本
function changePage(page, total) {
$.ajax({
url: '/public/ajax.php?do=getPageView',
type: 'POST',
dataType: 'json',
data: {
page: page,
total: total,
//type : type
},
success: function(data) {
//console.log(data.result);
if (data.result == 1) {
$('#placeHolder').html(data.html);
$('#vrouwen').html(data.html2);
} else if (data.status == 2) {
//do nothing :) - nothing has been input
} else {
alert("Fout!!\n" + textStatus + "\n" + errorThrown);
}
},
error: function error(jqXHR, textStatus, errorThrown) {
alert("Fout!!\n"
+ textStatus + "\n" + errorThrown);
}
});
};
function changePage(page, total) {
var ajax = new Request({
async: false,
url: '/public/ajax.php?do=getPageView',
method: 'POST',
dataType: 'json',
data: {
'page': page,
'total': total,
//type : type
},
onSuccess: function(data) {
//console.log(data.result);
if (data.result == 1) {
$('placeHolder').set('html', data.html);
$('vrouwen').set('html', data.html2);
} else if (data.status == 2) {
//do nothing :) - nothing has been input
} else {
//alert("Fout!!\n" + textStatus + "\n" + errorThrown);
}
}
});
ajax.send();
};
我的脚本版本
function changePage(page, total) {
$.ajax({
url: '/public/ajax.php?do=getPageView',
type: 'POST',
dataType: 'json',
data: {
page: page,
total: total,
//type : type
},
success: function(data) {
//console.log(data.result);
if (data.result == 1) {
$('#placeHolder').html(data.html);
$('#vrouwen').html(data.html2);
} else if (data.status == 2) {
//do nothing :) - nothing has been input
} else {
alert("Fout!!\n" + textStatus + "\n" + errorThrown);
}
},
error: function error(jqXHR, textStatus, errorThrown) {
alert("Fout!!\n"
+ textStatus + "\n" + errorThrown);
}
});
};
function changePage(page, total) {
var ajax = new Request({
async: false,
url: '/public/ajax.php?do=getPageView',
method: 'POST',
dataType: 'json',
data: {
'page': page,
'total': total,
//type : type
},
onSuccess: function(data) {
//console.log(data.result);
if (data.result == 1) {
$('placeHolder').set('html', data.html);
$('vrouwen').set('html', data.html2);
} else if (data.status == 2) {
//do nothing :) - nothing has been input
} else {
//alert("Fout!!\n" + textStatus + "\n" + errorThrown);
}
}
});
ajax.send();
};
在视图中,我有一个名为placeholder的div,这就是分页栏所在的位置。
html2被插入到div中,id='vrouwen'
希望你们能帮我解决这个问题
--编辑---
在与几个程序员同事进行头脑风暴后,我找到了答案。将调查结果发布在此处,供所有人查看
区别在于Jquery和Mootools处理返回值的方式
当您设置数据类型:“JSON”时,JQuery显然会将返回的值作为JSON对象处理。
Mootools没有这样做,因此我在onSuccess函数中添加了以下内容:
onSuccess: function(data) {
data = JSON.decode(data);
//console.log(data.html2);
if (data.result == 1) {
$('placeHolder').set('html', data.html);
$('vrouwen').set('html', data.html2);
} else if (data.status == 2) {
//do nothing :) - nothing has been input
} else {
//alert("Fout!!\n" + textStatus + "\n" + errorThrown);
}
}
现在它正确地替换了div
Mootool是一个XMLHttpRequest包装器
onSuccess
当请求成功完成时,将触发附加方法
返回到附加处理程序的参数是responseText
&responseXML
responseText-(字符串)请求返回的文本。
responseXML-(混合)来自请求的响应XML
-自动接收已包装的请求
JSON格式的JavaScript对象。意味着它是为json请求而创建的
当它接收到数据时,会将其转换为json对象
此处onSuccess
在请求完成时激发这将覆盖请求成功事件的签名。
返回到附加处理程序的参数是responseJSON
&responseText
responseJSON-(object)来自远程请求的JSON响应对象。
responseText-(string)JSON响应为string。仅供参考,MooTools还有一个名为的类。欢迎将您的发现作为答案发布。如果您有其他MooTools问题,请发回。不允许将我的发现作为答案发布,因为如果帖子发布时间少于8小时,需要10名代表对自己的帖子发表评论。您始终可以发布答案。你需要的是声誉,而不是答案。