传递jQuery的变量AJAX功能
问题描述:
这是我的功能传递jQuery的变量AJAX功能
$("body").on('click','.btn-info', function(e){
var email = [];
$('input[type="checkbox"]:checked').each(function(){
email.push($(this).parent().siblings().eq(2).text());
});
alert(email);
$.ajax({
type: "GET",
url: 'http://birdys.app/admin/sendpromocode',
data: JSON.stringify(email),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
alert('data');
}
function errorFunc() {
alert('error');
}
/** $.get('http://birdys.app/admin/sendpromocode',email,function(data){
alert(data);
},'json');*/
});
我得到复选框的电子邮件值点击和价值传递给我的AJAX功能,但它亘古不变的工作对我来说我怎样才能得到里面的AJAX这个值功能..
答
在使用前将您的数据字符串化。你可以在你的点击监听器中调用下面的函数,如getDetails(email)
。另请参阅安慰error
了解更多信息。
function getDetails(data) {
$.ajax({
type: "GET",
url: 'http://birdys.app/admin/sendpromocode',
data: {emailList: data},
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
//success callback
}
function errorFunc(xhr, error) {
console.log(error);
console.log(xhr);
}
}
而且,在这里 - >$.get('url',email,function(data){
因为URL是一个变量,不需要引用
你为什么引用网址?不需要''' – Ninjaneer