Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MicoAye's avatar

Ajax, no data available on display. Im having a hard time determining what is wrong

$(function () { loadDentalTable()

$('#addNewDentalCaseForm').on('submit', function (e) {
	e.preventDefault() // prevent page refresh
	addNewDentalCase()
})
	// pass data to API for updating 
	updateDentalAJAX($('#edit_user_id').val())
})

addNewDentalCase = () => { // New Dental Case if ($('#addNewDentalCaseForm')[0].checkValidity()) { // no validation error const form = new FormData($('#addNewDentalCaseForm')[0])

	data = {
		consultation_reason: form.get('consultation_reason'),
		health_appointment_assigned_to_physician: form.get('health_appointment_assigned_to_physician'),
		symptoms_date: form.get('symptoms_date'),
		consultation_date: form.get('consultation_date'),
		consultation_time: form.get('consultation_time'),
	}

	$.ajax({
		url: apiURL + 'omsss/student/add_appointment',
		type: 'POST',
		data: data,
		dataType: 'json',
		headers: AJAX_HEADERS,
		success: (result) => {
			if (result) {
				Swal.fire({
					html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/lupuorrc.json" trigger="loop" colors="primary:#0ab39c,secondary:#405189" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Well done !</h4><p class="text-muted mx-4 mb-0">You have successfully added a PUP Staff!</p></div></div>',
					showCancelButton: !0,
					showConfirmButton: !1,
					cancelButtonClass: 'btn btn-primary w-xs mb-1',
					cancelButtonText: 'Ok',
					buttonsStyling: !1,
					showCloseButton: !0,
				}).then(function () {
					$('#addDentalModal').modal('hide')
					$('form#addNewDentalCaseForm')[0].reset()

					// Reload Medical Consultation Datatable
					loadDentalTable()
				})
			}
		},
	}).fail(() => {
		Swal.fire({
			html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/tdrtiskw.json" trigger="loop" colors="primary:#f06548,secondary:#f7b84b" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Something went Wrong !</h4><p class="text-muted mx-4 mb-0">There was an error while adding a PUP Staff. Please try again.</p></div></div>',
			showCancelButton: !0,
			showConfirmButton: !1,
			cancelButtonClass: 'btn btn-primary w-xs mb-1',
			cancelButtonText: 'Dismiss',
			buttonsStyling: !1,
			showCloseButton: !0,
		})
	})
}

}

// Load datatables loadDentalTable = () => { const dt = $('#dental-datatable')

$.ajaxSetup({
	headers: {
		Accept: 'application/json',
		Authorization: 'Bearer ' + TOKEN,
		ContentType: 'application/x-www-form-urlencoded',
	},
})

if (dt.length) {
	dt.DataTable({
		bDestroy: true,
		ajax: {
			url: apiURL + 'omsss/student/view_dental_appointment',
			type: 'GET',
			ContentType: 'application/x-www-form-urlencoded',
		},
		columns: [
			// Case Control No.
			{
				data: null,
				render: (data) => {
					const caseNo = data.case_control_number
					return `${caseNo}`
				},
			},

			// Symptoms Date
			{
				data: null,
				render: (data) => {
					const sympDate = data.symptoms_date

					return `${sympDate}`
				},
			},

			// Status
			{
				data: null,
				render: (data) => {
					return data.is_blacklist
						? `<span class="badge rounded-pill bg-warning">Pending</span>`
						: `<span class="badge rounded-pill bg-success">Approved</span>`
				},
			},

			// Attending Consultant
			{
				data: null,
				render: (data) => {
					const healthPhysician = data.user_profiles.full_name
					return `${healthPhysician}`
				},
			},

			// Schedule
			{
				data: null,
				render: (data) => {
					const consultation = moment(data.consultation_date + data.consultation_date).format('LL')
					return `${consultation}`
				},
			},
		],
		order: [[0, 'asc']],
	})
}

}

// View Dental Consultation details viewDentalDetails = (user_id) => { $.ajaxSetup({ headers: { Accept: 'application/json', Authorization: 'Bearer ' + TOKEN, ContentType: 'application/x-www-form-urlencoded', }, })

$.ajax({
	type: 'GET',
	cache: false,
	url: apiURL + `omsss/student/view_dental_appointment${user_id}`,
	dataType: 'json',
	success: (result) => {
		const userData = result.data
		const userProfileData = result.data.user_profiles

		$('#view_case_details').html(userData.case_control_number)
  $('#view_consultation_reason').html(userData.consultation_reason)
		$('#view_health_physcian').html(userProfileData.full_name)
  $('#view_date_of_symptoms').html(userData.symptoms_date)
		$('#view_consultation_date').html(userData.consultation_date)
		$('#view_consultation_time').html(userData.consultation_time)
  $('#view_status').html(
			userData.is_blacklist
				? '<span class="fs-12 badge rounded-pill bg-warning" >Pending</span>'
				: '<span class="fs-12 badge rounded-pill bg-success" >Approved</span>',
		)
	},
})

}

0 likes
3 replies
vincent15000's avatar

Have you tried to write the datas in the console ?

console.log(yourDatasToDisplay);

Just to check if you really retrieved datas via the ajax request.

Snapey's avatar

I'm having a hard time

So are we. You say nothing about what actually happens.

Tell me, how do you create this much code without testing it as you go?

jlrdw's avatar

Why aren't you using your network tab developer tools to help troubleshoot this.

Please or to participate in this conversation.