从原型更改为jQuery [英] Changing from Prototype to jQuery
本文介绍了从原型更改为jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下要更改为jQuery的原型代码.
I have the following Prototype code which I want to change to jQuery.
在我看来,除了Ajax.Updater以外,其他所有代码都可以在jQuery中使用.但是我很可能错了.
It seems to me that except Ajax.Updater all other code can be used in jQuery. But I most probably wrong.
function jsUpdateCart(){
var parameter_string = '';
allNodes = document.getElementsByClassName("process");
for(i = 0; i < allNodes.length; i++) {
var tempid = allNodes[i].id;
var temp = new Array;
temp = tempid.split("_");
var real_id = temp[2];
var real_value = allNodes[i].value;
parameter_string += real_id +':'+real_value+',';
}
var params = 'ids='+parameter_string;
var ajax = new Ajax.Updater(
'ajax_msg','http://127.0.0.1/codeigniter_shopping/index.php/welcome/ajax_cart', {method:'post',parameters:params,onComplete:showMessage}
);
}
function showMessage(req){
$('ajax_msg').innerHTML = req.responseText;
location.reload(true);
}
function jsRemoveProduct(id){
var params = 'id='+id;
var ajax = new Ajax.Updater(
'ajax_msg','http://127.0.0.1/codeigniter_shopping/index.php/welcome/ajax_cart_remove', {method:'post',parameters:params,onComplete:showMessage}
);
}
推荐答案
在 ajax
方法可以轻松地将您的Ajax.Updater
调用转换为jQuery等效项:
A quick look through the jQuery documentation on the ajax
method would make it easy to convert your Ajax.Updater
calls into the jQuery equivalent:
$.ajax( {
type: 'post',
url: "<your_long_url>/ajax_cart",
data: params,
success: function( r ) {
$('#ajax_msg').html( r );
location.reload( true );
}
} );
这篇关于从原型更改为jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文