Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load data with AJAX? #65

Open
pixelzdesign opened this issue Jun 26, 2018 · 1 comment
Open

How to load data with AJAX? #65

pixelzdesign opened this issue Jun 26, 2018 · 1 comment

Comments

@pixelzdesign
Copy link

I need to load event data with AJAX for current month and when click on prev or next month to load data with ajax for those months.

@opiums9
Copy link

opiums9 commented Jun 22, 2022

In PHP example:

if($_GET['json']){
	header('Content-Type: application/json');
	$dbc = new DataBase();
	$stmt = $dbc->connect()->prepare("SELECT * FROM `calendar` ORDER BY `Date` ASC");
	$stmt->execute();
	$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	$json = array();
	if(!empty($result)){
		foreach($result as $row){
			$json[] = array(
				$row['Date'] => array(
					'content' => $row['content'],
					'repeat' => $row['repeats'],
					'allDay' => $row['allDay'],
					'endDate' => $row['endDate'],
				),
			);
		}
	}
	$dbc->disconnect();
	echo json_encode($json);
	exit();
}

and JS example:

		function ajaxCalendar(){
			$.get('hand.php', {json:1}, function(data){
				var result = {};
				data.forEach(function(v,i){
					result[Object.keys(v)] = Object.values(v);
				});
				$('#calendar').calendario({
					caldata: result,
					displayWeekAbbr: true,
					events: ['click', 'focus']
				});
			});
		}
		ajaxCalendar();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants