I am trying to fetch events from an external php file onto the full calendar view. I had asked a similar question sometime back but I am still struggling with this thing.
CODE (JS):
<script>
$(document).ready(function() {
$('#ccategory').change(function(){
var id = $(this).val();
var user = $('#current_user').val();
var calendar = $('#calendar').fullCalendar({
events: {
url: '<?php echo get_site_url(); ?>/get_calcat_calendar.php',
data: function() { // a function that returns an object
return {
dynamic_value1: id,
dynamic_value2: user
};
}
error: function() {
alert('There was an error while fetching events.');
}
}
});
});
});
</script>
Also I am going to add the file which is generating the json file below:
PHP CODE:
while($row = mysqli_fetch_assoc($result)){
$title = get_the_title($row['ID']);
$url = get_permalink($row['ID']);
$e = array();
$e['title'] = $title;
$e['url'] = $url;
$e['start'] = $row['start_date'];
$e['end'] = $row['end_date'];
$e['color'] = '#33cc33';
array_push($events, $e);
}
echo json_encode($events);
exit();
This is the code which I am using the fetch the json from the database. Any help will be greatly appreciated. Thank You
REQUIREMENT UPDATE:
[{"title":"Timeout72","url":"http:\/\/www.goawebsites.com\/goacalendar\/event\/timeout72\/","start":"2017-11-29","end":"2017-12-31","color":"#33cc33"}]
<div id='calendar'></div>
OTHER CALENDAR SCRIPT:
<script>
$(document).ready(function() {
var user_id = $('#current_user').val();
$('#calendar').fullCalendar({
displayEventTime: false,
events: [
<?php foreach($result as $r) { ?>
{
<?php $title = get_the_title($r['event_id']); ?>
<?php $url = get_permalink($r['event_id']); ?>
title: '<?php echo html_entity_decode($title); ?>',
start: '<?php echo $r['start_date'] ?>',
end: '<?php echo $r['end_date']." 23:59:59" ?>',
url: '<?php echo $url; ?>',
color: '#33cc33'
},
<?php } ?>
]
});
});
</script>
This should be more like what you need:
1) When you first set up your calendar, define your extra "user" and "category" data parameters dynamically (using a callback function).
2) Inside your category "change" event, all you need to do now is simply tell the calendar to refetch the events. There is no need to completely re-initialise the calendar, as you have been doing.
I can't see all of the code, including where you first initialise the calendar, so this may not be 100% accurate, but this is the general idea:
$(document).ready(function() {
$('#calendar').fullCalendar({
events: {
url: '<?php echo get_site_url(); ?>/get_calcat_calendar.php',
data: function() { //using a callback function here allows fullCalendar to fetch the latest values of these parameters every time it makes a new request to the server, rather than them being supplied statically at initialisation
return {
id: $('#ccategory').val(),
user: $('#current_user').val()
};
},
error: function() {
alert('There was an error while fetching events.');
}
}
});
$('#ccategory').change(function() {
//just tell the calendar re-fetch the events. It will automatically get the latest category ID value and send it to the server as a parameter
$("#calendar").fullCalendar("refetchEvents");
});
});
This is based on the pattern shown in the "Dynamic data parameter" section in the documentation at https://fullcalendar.io/docs/event_data/events_json_feed/
Related
I am trying to make updating variable called $online without refreshing site.
Theres is my try:
data.php
<?php
include("steam.php");
$data = $online;// obtain current value of data from somewhere
echo $data; // should be an integer
?>
refresh.js
$(document).ready( function () {
var data = []; // data is empty
var graph = Morris.Bar({
element: 'graph',
data: data
labels: ['random label']
});
function update () {
$.getJSON( "data.php", function (newv) {
data.push( { x: newv, y: "Today" } ); // store new value
graph.setData( data ); // update the graph
});
}
update();
setInterval( update, 1000 );
});
I just ran this through so I know it works. My previous comment will do the job. I know $.getJSON is similar so I don't know what conflicts you will have there, but the below will update your php variable.
<script>
$.post( "data.php", { online: "UpdatedData" } );
</script>
data.php
$online = $_POST['online'];
I have some <td name="puja"> elements I want to update every 5 seconds deppending on their id so they contain the greatest bid(puja) for it's auction(subasta). For that, I'm trying to use AJAX and PHP.
Html looks like this (relevant code):
<?php
foreach ($subastas as $subasta) { ?>
<td name="puja" id="<?php echo $subasta["oid_s"] ?>"> </td>
As I have multiple elements to update, I tried getting all the elements and then running my AJAX function for every one of them.
AJAX:
$(document).ready(function()
{
var ids = document.getElementsByName("puja");
for (var i=0; i<ids.length;i++){
var id = ids[i].id;
$.ajax({
url : 'includes/getPuja.php',
data:{"oid_s":id},
success: function(data){
$(`#${id}`).html(data);
}
});
};
});
Finally, in my php file I just make a database connection, get the desired value , and echo it.
getPuja.php (relevant code):
$puja = 0;
if(isset($_POST["oid_s"])) {
$oid_s = $_POST["oid_s"];
$consultaPuja='SELECT pujado from (SELECT * from pujas WHERE OID_S = :oid_s ORDER BY pujado DESC) where rownum = 1';
try {
$stmtPuja = $conexion->prepare($consultaPuja);
$stmtPuja -> bindParam(':oid_s', $oid_s);
$stmtPuja -> execute();
foreach ($stmtPuja as $fila) {
$puja = $fila["PUJADO"] ;
}
echo $puja;
} catch(PDOException $e) {
$_SESSION["excepcion"] = $e -> GetMessage();
header("Location: excepcion.php");
}
}
When I run it, the HTML is not modified.
I fixed my problem with the following code, now the values get updated every second:
$(document).ready(function(){
setInterval(getPuja, 1000);
function getPuja() {
$( '[name=puja]' ).each(function() {
var id = $( this ).attr('id');
$.ajax({
url : 'includes/getPuja.php',
method:"POST",
data:{oid_s:id},
success: function(data){
$(`#${id}`).html(data);
}
});
});
}
});
I am working with SugarCRM API for get_module_fieldsand displaying its results in Checkbox You can check here . I have saved some checkbox value in database using AngularJS checklist-model and now I want to update it.So for that I want to display saved checkbox as checked but I unable to do that.Is any one can tell me how to do that?
here is my script code and i dont know what to write in $scope.users.mod_fields so that i can display checked checkbox
<script>
var app = angular.module("myApp", ["checklist-model"]);
app.controller('myCtrl', function($scope,$http) {
$scope.users = {};
$scope.users.mod_name = '<?php echo $module_name;?>';
$scope.users.mod_id = '<?php echo $module_id;?>';
$scope.users.mod_fields ='';
$scope.updateModule=function(){
$http.post("update_modulelist.php", {'mod_id':$scope.users.mod_id,'mod_name':$scope.users.mod_name, 'mod_fields' : $scope.users.mod_fields})
.success(function(data,status,headers,config){
alert(JSON.stringify(data));
//alert("Data Inserted Successfully");
window.location.href="show_modulelist.php";
});
}
});
</script>
You haven't put the HTML code, but to update this, you actually need to modify the checklistModel, not ngChecked or ngModel.
Done like this & got perfect answer:
var app = angular.module("myApp", ["checklist-model"]);
app.controller('myCtrl', function($scope,$http) {
$scope.users = {
mod_fields: '<?php foreach ($items as $key=>$val) { echo $val.',';}?>'
};
$scope.users.mod_name = '<?php echo $module_name;?>';
$scope.users.mod_id = '<?php echo $module_id;?>';
$scope.users.mod_fields = <?php
$module_fields = $_GET['fields'];
$module_fie =explode(',',$module_fields);
json_encode($module_fie);
echo json_encode($module_fie) ?>;
$scope.updateModule=function(users){
$http.post("update_modulelist.php", {'mod_id':$scope.users.mod_id,'mod_name':$scope.users.mod_name, 'mod_fields' : $scope.users.mod_fields})
.success(function(data,status,headers,config){
window.location.href="show_modulelist.php";
});
}
});
I am trying create map with amCharts using jquery ajax but it doesnt work with ajax.
here my ajax code:
$('button#btn').click(function(){
$('div#ozellikli').html('<center><img src="assets/img/loading.gif" width="200" height="200"/></center>')
$.ajax({
type:'post',
url:'ozellikliAjax.php',
data:$('form#oz').serialize(),
success:function(msg){
$('div#ozellikli').html(msg);
}
});
});
Here my ajax php code:
<?php
include 'config.php';
$html="";
$yil=$_POST['yil'];
$tur=$_POST['tur'];
///HARITAYI CIZ
$sql="SELECT id,il,COUNT(kurum) AS kurum_Say FROM ozellikli GROUP BY id,il ORDER BY kurum_Say";
$result=$baglanti->query($sql);
$mapChart="";
while ($query=$result->fetch(PDO::FETCH_ASSOC)) {
$mapChart.=' { title: "'.$query['il'].':'.$query['kurum_Say'].'", id: "TR'.$query['id'].'",value:'.$query['kurum_Say'].', selectable: true },';
}
$html.='<script type="text/javascript">
AmCharts.ready(function() {
var map;
// *** CREATE MAP ***********************************************************
function createMap(){
map = new AmCharts.AmMap();
map.pathToImages = "http://www.ammap.com/lib/images/";
//map.panEventsEnabled = true; // this line enables pinch-zooming and dragging on touch devices
var dataProvider = {
mapVar: AmCharts.maps.turkeyLow
};
map.areasSettings = {
unlistedAreasColor: "#43B1A9",
rollOverOutlineColor: "#FFFFFF"
};
map.colorSteps=5;
map.valueLegend={
left: 10,
bottom:0,
minValue: "En Az",
maxValue: "En Çok"
};
dataProvider.areas = ['.$mapChart.'];
map.dataProvider = dataProvider;
map.addListener(\'clickMapObject\', function (event) {
// deselect the area by assigning all of the dataProvider as selected object
map.selectedObject = map.dataProvider;
// toggle showAsSelected
event.mapObject.showAsSelected = !event.mapObject.showAsSelected;
// bring it to an appropriate color
map.returnInitialColor(event.mapObject);
var states = [];
for (var i in map.dataProvider.areas) {
var area = map.dataProvider.areas[i];
if (area.showAsSelected) {
states.push(area.title);
}
}
});
map.write("mapdiv");
}
createMap();
});
</script>';
echo $html;
?>
when run the ajax code , script loading with ajax correctly but its not charting to map.
How can I solve this issue?
thanks
If you inject the resources the same way, you need to set manually it's ready state otherwise it won't work. AmCharts listens to the dom loaded event to set following property:
AmCharts.isReady = true;
I'm working with Symfony 1.4 and we have a problem with IE7
We have a form and an url, when we click the url we want to display a copy of the first form.
Number maximum of forms to display is 3
Now the problem is when we click the first time the second form display. But in the third time it blocks.
Here is the AJAX script:
<script type="text/javascript">
$('a#add_contact_anchor').click( function() {
var select_default_values = new Array();
var array_counter = 0;
$(this).parents('div#activity_contact_container').find('input').each( function(){
select_default_values[array_counter] = { value: $(this).val(), name: $(this).attr('id')};
array_counter++;
});
$(this).parents('div#activity_contact_container').find('select').each( function(){
select_default_values[array_counter] = { value: $(this).val(), name: $(this).attr('id')};
array_counter++;
});
var params = { default_contact_values: select_default_values, contact_num: <?php echo $contact_num; ?> };
ajaxCallObj = { page: '<?php echo url_for('myCommunication/updateContactsForCatalog', true); ?>', data: params, update: '#activity_contact_container' };
ajaxCall(ajaxCallObj);
});
</script>
And here is the url :
<a title="<?php echo __('Add new contact 3019'); ?>" href="javascript:void(0);" id="add_contact_anchor"><?php echo __('Add new contact 3019'); ?></a>
Try and move the counter outside the click function callback, probably you're just continuing overwriting the second form.