原型到 jQuery 转换混乱
Prototype to jQuery Conversion Confusion
我有以下功能:
function updateproductselectionxxx(form, productassignment, mainproductid, subprodqty) {
var checkingurl = "shopajaxproductselection.asp";
var pars = 'productassignment=' + productassignment + '&qty=' + subprodqty + '&mainid=' + mainproductid;
var url = checkingurl + '?' + pars;
var target = 'productselectionresult' + productassignment;
var myAjax = new Ajax.Updater(target, checkingurl, {
method: 'post',
parameters: pars
});
}
我目前正在将本网站上的所有 javascript 转换为 jQuery。通常我可以使用类似的东西:
function updateproductselection(form, productassignment, mainproductid, subprodqty) {
$.ajax({
type: 'POST',
url: 'shopajaxproductselection.asp',
data: $(form).serialize(),
success: function (response) {
$(form).find('productselectionresult' + productassignment).html(response);
}
});
return false;
}
这就是诀窍,但我真的只想发送第一个函数中指示的 1 个字段,我还想在函数被调用时将我直接发送的信息一起发送。 JavaScript 绝对不是我的专业领域,但通常我可以蒙混过关,但这次我尝试的一切都导致了错误,我并没有走得太远。任何帮助将不胜感激。
看起来 POST 和 GET 有点混淆。虽然请求方法在较旧的原型版本中设置为 POST
,但参数是通过 CGI 发送的,通常在服务器上显示为 GET
。在没有看到服务器端代码的情况下很难说更多,但你可以试试这个,这样 jQuery 版本更接近于旧的 Prototype 版本:
function updateproductselection(form, productassignment, mainproductid, subprodqty) {
var checkingurl = "shopajaxproductselection.asp";
var pars = 'productassignment=' + productassignment + '&qty=' + subprodqty + '&mainid=' + mainproductid;
var url = checkingurl + '?' + pars;
$.ajax({
type: 'POST',
url: url,
data: {},
success: function (response) {
$(form).find('#productselectionresult' + productassignment).html(response);
}
});
return false;
}
请注意,我在 productselectionresult
的开头添加了一个散列 #
- 由于 PrototypeJS 工作方式的不同,这很重要。在 Prototype 中,您可以使用 ID 选择器,例如:
$('id')
而在 jQuery 中它必须是:
$('#id')
我有以下功能:
function updateproductselectionxxx(form, productassignment, mainproductid, subprodqty) {
var checkingurl = "shopajaxproductselection.asp";
var pars = 'productassignment=' + productassignment + '&qty=' + subprodqty + '&mainid=' + mainproductid;
var url = checkingurl + '?' + pars;
var target = 'productselectionresult' + productassignment;
var myAjax = new Ajax.Updater(target, checkingurl, {
method: 'post',
parameters: pars
});
}
我目前正在将本网站上的所有 javascript 转换为 jQuery。通常我可以使用类似的东西:
function updateproductselection(form, productassignment, mainproductid, subprodqty) {
$.ajax({
type: 'POST',
url: 'shopajaxproductselection.asp',
data: $(form).serialize(),
success: function (response) {
$(form).find('productselectionresult' + productassignment).html(response);
}
});
return false;
}
这就是诀窍,但我真的只想发送第一个函数中指示的 1 个字段,我还想在函数被调用时将我直接发送的信息一起发送。 JavaScript 绝对不是我的专业领域,但通常我可以蒙混过关,但这次我尝试的一切都导致了错误,我并没有走得太远。任何帮助将不胜感激。
看起来 POST 和 GET 有点混淆。虽然请求方法在较旧的原型版本中设置为 POST
,但参数是通过 CGI 发送的,通常在服务器上显示为 GET
。在没有看到服务器端代码的情况下很难说更多,但你可以试试这个,这样 jQuery 版本更接近于旧的 Prototype 版本:
function updateproductselection(form, productassignment, mainproductid, subprodqty) {
var checkingurl = "shopajaxproductselection.asp";
var pars = 'productassignment=' + productassignment + '&qty=' + subprodqty + '&mainid=' + mainproductid;
var url = checkingurl + '?' + pars;
$.ajax({
type: 'POST',
url: url,
data: {},
success: function (response) {
$(form).find('#productselectionresult' + productassignment).html(response);
}
});
return false;
}
请注意,我在 productselectionresult
的开头添加了一个散列 #
- 由于 PrototypeJS 工作方式的不同,这很重要。在 Prototype 中,您可以使用 ID 选择器,例如:
$('id')
而在 jQuery 中它必须是:
$('#id')