[英]Passing a variable from anchor click to ajax
I am using opencart and got stuck. 我正在使用opencart并被卡住。 What I am doing is sending some variable to ajax.
我正在做的是向ajax发送一些变量。 This is my data:
这是我的数据:
data: $('.product-block input[type=\'text\'], .product-block input[type=\'hidden\'], .product-block input[type=\'radio\']:checked, .product-block input[type=\'checkbox\']:checked, .product-block select, .product-block textarea'),
It is working fine. 一切正常。 But what I need to do is to replace the '.product-block' from picking a id from anchor click.
但是我需要做的是替换从锚定点击中选择ID的“ .product-block”。
I have my id here 我的身份证在这里
var id = $(this).attr('rel');
But I am unable to build the data source from this link. 但是我无法从此链接构建数据源。 I am using it like this:
我正在这样使用它:
data: $(id + ' input[type=\'text\']', id + ' input[type=\'hidden\']', ... ),
and tested this 并测试了
data: $(id + ' input[type=\'text\']', + id + ' input[type=\'hidden\']', ... ),
But it is not working. 但这是行不通的。 Can someone help me?
有人能帮我吗?
Remove all ".product-block" occurrences and use find()
it's simpler: 删除所有出现的“ .product-block”并使用
find()
更简单:
var id = "#" + $(this).attr('rel');
$(id).find('input[type=\'text\'], input[type=\'hidden\'], input[type=\'radio\']:checked, input[type=\'checkbox\']:checked, select, textarea');
Also don't forget to use serialize()
to "pull" the data from the form: 同样不要忘记使用
serialize()
从表格中“拉出”数据:
data: $(id).find(...).serialize() //removed ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.