我在下面的代碼中有一些條件變量。例如,如果var shipping ==「true」,則存在shippingAddress1,shippingAddress2等。但是,如果shipping ==「false」,這些變量是未定義的,並留空。我的問題是,當我嘗試發佈時,由於某些變量未定義,我收到了一個js錯誤。有沒有辦法將這些通過空白?更改AJAX未定義變量,以便發佈將工作
$.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
},
如果您正在尋找窗體域,用[連載](http://api.jquery.com/serialize/) – epascarello