Add events in viewRender fullcalendar - php

how can i add new events using URL in viewRender?
viewRender: function(view, element){
}
how can i add events using a URL?
i want to do something like this?:
$.ajax({
url: 'http://www.example.com/get-events.php',
type: 'POST', // Send post data
success: function (events) {
console.log(events);
},
fail: function() {
alert('There was an error while fetching events.');
}
});
and i want to add the events in my calendar. how can i do that?

Related

jQuery toggle with different attributes and apply ajax

I am using this jQuery plugin for making toggle, but I have an issue that when I make multiple toggles that have same ids and class so in that case I am not able to identify particular toggle for applying auto load ajax on changing value.
I would to ask that how I make same toggle with this same plugin but different ids or class or name so I make ajax function like when I click toggle it will update in PHP without submitting submit button.
The plugin I am using is this one
The code I am using is this:
HTML
<p>Default: <span class="easyswitch"></span></p>
<p>Checked: <span class="easyswitch" data-default="1"></span></p>
SCRIPT
<script>
$('.easyswitch').easyswitch();
</script>
AJAX
$('MY_CLASS_NAME').change(function(){
var mode= $(this).prop('checked');
$.ajax({
type:'POST',
dataType:'JSON',
url:'test.php',
data:'mode='+mode,
success:function(data)
{
$("body").html('Operation Saved');
}
});
You can not handle easyswitch's change event. you need to create click event of it, and from it you can get the status of current toggle.
$('.easyswitch').easyswitch();
$('.easyswitch').click(function () {
var mode = $(this).hasClass('on');
toogleStatus(mode);
});
// for all controlls.
$(".easyswitch").each(function() {
var mode = $(this).hasClass('on');
toogleStatus(mode);
});
function toogleStatus(mode)
{
if (!mode) {
alert('checked')
}
else {
alert('unchecked')
}
}
Try using callback option
$('.easyswitch').easyswitch({
callback: function(val, ele) {
$.ajax({
type: 'POST',
dataType: 'JSON',
url: 'test.php',
data: { mode: val },
success: function(data) {
$("body").html('Operation Saved');
}
});
}
});

500 (Internal Server Error) in ajax data posting laravel 5.4

hi i am trying to post some values on drop down change and fetch data form database on the base of that value and return back the ajax response .
like i want to get all branches of that specific company when i change company by drop-down, branches of that specif company displayed in drop down in a specific area
but i am facing 500 (Internal Server Error). Always displays i am an error in console. My jQuery is
$(".select-company").dropdown({
onChange: function (val) {
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
var id=val;
var urll = "promoplan/getcity";
$.ajax
({
type: "POST",
url: urll,
data: { company_id: id, _token: CSRF_TOKEN },
cache: false,
success: function(html)
{
console.log(html);
//$("#regions").html(html);
},
error: function()
{
console.log('i am an error');
}
});
}
});
My Route is
Route::post('promoplan/getcity','PromotionPlanController#getcity');
In your controller you have to incude following
use Response;
Can you try var urll = "promoplan/getcity"; to urll = "/promoplan/getcity";

Adding events in JSON to fullcalendar

I am trying to add events into my fullcalendar calendar with my json string. here is my code:
viewRender: function(view, element){
$.ajax({
url: 'http://www.example.com/get-events-json.php',
type: 'POST',
success: function (data) {
$('#calendar').fullCalendar('addEventSource', data);
},
fail: function() {
alert('There was an error while fetching events.');
}
});
}
});
in my success, data is:
[{"title":"John Bobby","start":"2017-05-16T15:30:00","end":"2017-05-16T15:30:00"},{title":"Jason Kaple","start":"2017-05-20T17:30:00","end":"2017-05-20T17:30:00"}]
i tried to add it using $('#calendar').fullCalendar('addEventSource', data); as you can see but i get an error message in my console:
http://www.example.com/[json (data)...] 404 (Not Found)
how can i fix this? are there any ways around this? thanks
You can also get the data from an ajax call and after the render add the elements with addEvent
function addEvent(title, date){
calendar.addEvent({
title: title,
start: date,
allDay: true,
color: 'green'
});
}
for(event of events){
addEvent(event.title, event.date)
}

How to Select Data from database using Ajax and Plugin Select2

Please help me to solve my problem.
$("#kategori_laporan").change(function() {
$("#loaderIcon").show();
$("#imgLoader").show();
var id = $(this).val();
$.ajax({
type: "POST",
dataType: "html",
url: "_views/getAjaxSubKategori.php",
data: "id="+id,
success: function(data) {
$(".select-skategori").select2({
ajax: {
url: "_views/getAjaxSubKategori.php",
dataType: 'json',
data: function(term, page) {
search = term.toUpperCase();
},
results: function(datas, page) {
return {
results: data
};
}
},
formatResult: function(option) {
return "<div>" +option._sub_kategori_laporan+ "</div>";
},
formatSelection: function(option) {
return option._sub_kategori_laporan;
}
});
}
});
});
Data not showing to subcategory select. Thanks before.!
Screenshot >> http://i.imgur.com/FlCeGpo.jpg
Why are you firing an ajax request before you initialize the select2 box?
I ask this, because your select2 box is requesting the search results via ajax as well. But maybe there is a reason. Please explain.
Then I can see in your screenshot, that your data returned from the json ajax request has not defined values id and text. If you are using other values ('_sub_kategori_id' and '_sub_kategori_laporan') in your json result, you have to tell the select2 box, what is your id and text field. I think you can do this with the processResults method as described here:
How to load JSON data to use it with select2 plugin

jQuery each() results to array to php to database

Basically what I am doing is making a sort of invitation system, the user clicks on users and they go into a list, that all works, I can get the ids of them using each() but I need to pass it through jQuery Ajax to php to send it to the database for notifications. This is basically what I have:
$(".group-video-create").click(function(){
var url = $(".group-input-url").val();
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&##\/%?=~_|!:,.;]*[-A-Z0-9+&##\/%=~_|])/ig;
var checked_url = url.match(exp,"<a href='$1'>$1</a>");
if(checked_url)
{
$("#group-input-names li").each(function(){ // This is the relevant code
var user_id = $(this).attr("id"); // Here too
}); // & here
if(user_id)
{
$.ajax({
type: "POST",
//url: "",
//data: "", //this would be an array of all of the ids, (could be 1, could be 100).
cache: false,
success: function(html){
///Once all invitations have been sent to the database it would then load a new div and hide the previous one.
}
});
}
}
});
if you want to see what I'm trying to accomplish just go here:
http://www.kithell.com/#/video
usr: PhpFreak#yahoo.com
pass: phpfreaklogin
It's under Group Video. (You should be automatically directed there once logged in)
You might be able to use jQuery.serialize to bundle up all of your form data. Also, jQuery.post is a nice shortcut for doing a POST request with jQuery.ajax.
A rough example might look this:
$.post( '/my-ajax-service.php',
$('#MyForm').serialize(),
function(data, txtStatus, jqXHR) {
//Do stuff
});
Here is one possibility
http://jsfiddle.net/nickywaites/9GZ2e/
$(function() {
//I would use jQuery Map to build Array
//http://api.jquery.com/map/
var ids = $("#group-input-names li").map(function() {
return $(this).attr("id");
}).get(); //Get Required to convert to regular javascript array
console.log(ids);
var invites = {}
invites.users = ids;
//Then use JSON.stringify() to pass array to server
//https://github.com/douglascrockford/JSON-js
if (ids.length > 0) {
$.ajax({
type: "POST",
//url: "",
data: JSON.stringify(invites),
cache: false,
success: function(html) {}
});
}
});

Categories