这是一个简单的检查和ajax发送功能
fcell
是单元格编号,v_cell
是前3位数,应该在091-3范围内。
所以我得到他们两个,当我提醒他们一切都好(虽然每个人得到3个警报)但是因为它发送ajax请求我得到这个错误
TypeError: fcell is undefined
[Break On This Error]
var v_cell = fcell.slice(0,3);
这是代码
var finprog = false;
$('.send_to_friend').click(function(){
var tr = $(this).parent().parent();
var p = $(this).parent();
var fcell = tr.find('.fcell').val();
var fname = tr.find('.fname').val();
var funame = tr.find('.funame').val();
var v_cell = fcell.slice(0,3);
alert(fcell);
alert(v_cell);
if(isNaN(fcell))
{
alert('error');
return false;
}
if(fcell.length != 11 )
{
alert('error');
return false;
}
if(v_cell != 091 && v_cell != 092 && v_cell != 093 )
{
alert('error');
return false;
}
if(fname.length == 0 )
{
alert('error');
return false;
}
if(funame.length == 0 )
{
alert('error');
return false;
}
if(finprog) return false;
finprog = true ;
var id = tr.attr('class');
p.html('<img src="images/load_square.gif" width="27" height="27" />');
$.post('aj.php' , { name:fname , uname:funame , cell:fcell , sms_id:id , doo : 'sent_to_friend' }
, function(data) {
finprog = false;
if($.trim(data) == 'ok')
{
p.html('ok');
}
else
{
p.html('error');
}
})
})
它没有任何意义
这是我的ajax参数。它在这里定义了! cell 09163105802
Parametersapplication/x-www-form-urlencoded
cell 09125105802
doo sent_to_friend
name x
sms_id 9
uname x
答案 0 :(得分:1)
您很可能收到此错误,因为您的tr对象为null。因此,当您尝试使用类fcell查找元素时,它也会返回null。
var tr = $(this).parent().parent();
// tr is most likely null here
var fcell = tr.find('.fcell').val();
// therefore fcell cannot be found and is undefined
如果是这种情况,我建议您使用以下内容查找tr。
var tr = $(this).closest('tr');