我可以通过定位表单类< form class =“my_form_class”>来处理我的表单值:
jQuery.ajax({
type:"GET",url: "/wp-admin/admin-ajax.php",data: my_form_class,context: this,success:function(data){
// do stuff
}
});
这非常有效.
但我想添加更多数据,所以我试过:
data: { my_form_class,security : 'foo' },
那没起效.我在这做错了什么?我试过了:
data: { my_form_class : my_form_class,
它显然也无效.
最佳答案
根据jQuery ajax的定义
data
Type: PlainObject or String or Array
Data to be sent to the server. It is converted to a query string,if not already a string. It’s appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array,jQuery serializes multiple values with same key based on the value of the traditional setting (described below).
您可以使用jquery param和jQuery serialize:
$('.my_form_class').serialize() + '&' + $.param({security : 'foo'});
我的片段:
$(function () {
$('#btn').on('click',function(e) {
console.log($('.my_form_class').serialize() + '&' + $.param({security : 'foo'}));
$.ajax({
type:"GET",data: $('.my_form_class').serialize() + '&' + $.param({security : 'foo'}),success:function(data){
// do stuff
}
}).fail(function(jqXHR,textStatus,errorThrown) {
console.log('ajax error: ' + textStatus)
});
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。