Skip to content

Instantly share code, notes, and snippets.

@npapratovic
Last active July 12, 2022 10:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npapratovic/4c7338c87e9df44efb79ff25f76d5848 to your computer and use it in GitHub Desktop.
Save npapratovic/4c7338c87e9df44efb79ff25f76d5848 to your computer and use it in GitHub Desktop.
On button click start function with ajaxcall to remote to fetch data and store data in another div
<a id="clickme">Click me!</a>
<div id="populateme"></div>
<script>jQuery(function ($) {
$(document).ready(function(){
var getdest = '/session/getdest';
$(document).on('click', '#clickme', function() {
changeDiv();
});
function changeDiv() {
$.ajax({
url: getdest,
type: 'POST',
//dataType: 'json',
data: {'id': 1},
success: function(response) {
//console.log(response);
$('#populateme').html(response);
},
error: function(xhr){
console.log("An error occured: " + xhr.status + " " + xhr.statusText);
}
})
}
})
})
</script>
<?php
public function actionGetdest() {
$session = \Yii::$app->session;
$date_range = $session['check-in'] . ' → ' . $session['check-out'];
echo $date_range;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment