【发布时间】:2012-02-19 04:40:03
【问题描述】:
我在下面的代码中有一些条件变量。例如,如果 var shipping == "true",则 shippingAddress1、 shippingAddress2 等存在。但是,如果 shipping == "false",则这些变量未定义,并留空。我的问题是,当我尝试发布时,我收到一个 js 错误,因为某些变量未定义。有没有办法通过空白发送这些?
$.post( 'reserveAPickupAppointmentCreatePickup.php', {
'location': appointmentLocation,
'appointmentAddress1': appointmentAddress1,
'appointmentAddress2': appointmentAddress2,
'serviceType': serviceType,
'shipping': shipping,
'shippingAddress1': shippingAddress1,
'shippingAddress2': shippingAddress2,
'shippingCity': shippingCity,
'shippingState': shippingState,
'shippingZip': shippingZip,
'startTime': startTime,
'endTime': endTime,
'date': date,
'estimatedSize': appointmentSize,
'highValueItems': highValueItems,
'insuredItems': insuredItems,
'tools': tools,
'presentAtAppointment': presentAtAppointment,
'contactName': contactName,
'contactPhone': contactPhone,
'contactEmail': contactEmail,
'itemList': itemList,
'studentPhone': studentPhone
},
【问题讨论】:
-
如果您正在查找表单字段,请使用serialize
标签: javascript jquery ajax post