Error Loading the following Javascript - javascript

Could someone please tell me what's wrong with the following code. I'm guessing it has something to do with missing brackets for the Javascript, but I can't put my finger on it. We're using Full Calendar + Mandrill
Thanks a lot!
$(window).load(function() {
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: 'prev,next today'
},
defaultDate: '2016-03-15',
events: [
{
title: 'Event',
start: '2016-03-26T11:00:00',
end: '2016-03-26T12:00:00',
},
],
eventClick: function(event) {
console.log(event)
// alert(event.start.format('MMMM Do YYYY'))
start = event.start.format('MMMM Do YYYY'),
end = event.end.format('MMMM Do YYYY'),
html = '<p>Starts: ' + start + '<p>';
html += '<p>Ends: ' + end + '<p>';
var modal = $("#modal");
modal.find(".modal-title").html(event.title);
modal.find('.modal-body').html(html)
modal.modal();
jQuery(function($) {
$("#contact_form").submit(function() {
var email = $("#email").val(); // get email field value
var name = $("#name").val(); // get name field value
var msg = $("#msg").val(); // get message field value
var content = "Hello "+name+ ", You have signed "+modal+ " up to XYZ";
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': 'api',
'message': {
'from_email': "email",
'text': "Hello ",
'from_name': "name",
'headers': {
'Reply-To': "email"
},
'subject': 'Confirmation - Sign Up',
'text': content,
'to': [{
'email': email,
'name': name,
'type': 'to'
}]
}
}
}
})
.done(function(response) {
alert('You have been signed up. Thank you!'); // show success message
$("#name").val(''); // reset field after successful submission
$("#email").val(''); // reset field after successful submission
$("#msg").val(''); // reset field after successful submission
})
.fail(function(response) {
alert('Error sending message.');
});
return false; // prevent page refresh
});
});
});
});
}); //]]>

First your code should have proper indentation,
You have some errors in the closing of braces and like so for eg: you have an extra closing brace in ajax call and few others, which I have corrected and pasted.
$(window).load(function() {
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: 'prev,next today'
},
defaultDate: '2016-03-15',
events: [
{
title: 'Event',
start: '2016-03-26T11:00:00',
end: '2016-03-26T12:00:00',
},
],
eventClick: function(event) {
console.log(event)
// alert(event.start.format('MMMM Do YYYY'))
start = event.start.format('MMMM Do YYYY'),
end = event.end.format('MMMM Do YYYY'),
html = '<p>Starts: ' + start + '<p>';
html += '<p>Ends: ' + end + '<p>';
var modal = $("#modal");
modal.find(".modal-title").html(event.title);
modal.find('.modal-body').html(html)
modal.modal();
}
)}
jQuery(function($) {
$("#contact_form").submit(function() {
var email = $("#email").val(); // get email field value
var name = $("#name").val(); // get name field value
var msg = $("#msg").val(); // get message field value
var content = "Hello "+name+ ", You have signed "+modal+ " up to XYZ";
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': 'api',
'message': {
'from_email': "email",
'text': "Hello ",
'from_name': "name",
'headers': {
'Reply-To': "email"
},
'subject': 'Confirmation - Sign Up',
'text': content,
'to': [{
'email': email,
'name': name,
'type': 'to'
}]
}
}
})
.done(function(response) {
alert('You have been signed up. Thank you!'); // show success message
$("#name").val(''); // reset field after successful submission
$("#email").val(''); // reset field after successful submission
$("#msg").val(''); // reset field after successful submission
})
.fail(function(response) {
alert('Error sending message.');
});
return false; // prevent page refresh
});
});
});
Please check now.

This is what you expect ?
$(window).load(function () {
$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: 'prev,next today'
},
defaultDate: '2016-03-15',
events: [
{
title: 'Event',
start: '2016-03-26T11:00:00',
end: '2016-03-26T12:00:00',
},
],
eventClick: function (event) {
console.log(event)
// alert(event.start.format('MMMM Do YYYY'))
start = event.start.format('MMMM Do YYYY'),
end = event.end.format('MMMM Do YYYY'),
html = '<p>Starts: ' + start + '<p>';
html += '<p>Ends: ' + end + '<p>';
var modal = $("#modal");
modal.find(".modal-title").html(event.title);
modal.find('.modal-body').html(html)
modal.modal();
}
});
});
});
jQuery(function ($) {
$("#contact_form").submit(function () {
var email = $("#email").val(); // get email field value
var name = $("#name").val(); // get name field value
var msg = $("#msg").val(); // get message field value
var content = "Hello " + name + ", You have signed " + modal + " up to XYZ";
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': 'api',
'message': {
'from_email': "email",
'text': "Hello ",
'from_name': "name",
'headers': {
'Reply-To': "email"
},
'subject': 'Confirmation - Sign Up',
'text': content,
'to': [{
'email': email,
'name': name,
'type': 'to'
}]
}
}
})
})
.done(function (response) {
alert('You have been signed up. Thank you!'); // show success message
$("#name").val(''); // reset field after successful submission
$("#email").val(''); // reset field after successful submission
$("#msg").val(''); // reset field after successful submission
})
.fail(function (response) {
alert('Error sending message.');
});
return false; // prevent page refresh
});

Related

Full calendar not showing events generated dynamically

My events are not getting displayed on fullcalendar. I am fetching the list of events from the backend server using nodejs. the events are getting generated dynamically. I am able to get the events in array but t he events are not showing on the calendar. Any help would be appreciated
function searchappointmentssss(forappdate) {
$.ajax({
url: 'http://localhost:3000/searchappointment',
type: 'post',
data: {
date: forappdate
},
dataType: 'json',
success: function(data) {
var aaaaaaa = [];
data.forEach(function(dataa) {
var ddddddd = dataa.date.split("T");
var appppppp = {};
appppppp.title = dataa.patientname + "\n" + dataa.purposeofvisit;
appppppp.description = dataa.purposeofvisit;
appppppp.start = ddddddd[0] + " " + dataa.time;
appppppp.end = ddddddd[0] + " " + dataa.endtime;
appppppp.id = dataa.appointmentid;
appppppp.visstatus = dataa.status;
appppppp.gicid = dataa.gic;
aaaaaaa.push(appppppp);
});
console.log(aaaaaaa);
$('#calendar').fullCalendar({
defaultView: "agendaDay",
defaultDate: "2018-10-26",
events: aaaaaaa,
eventTextColor: '#ffffff',
header: {
left: 'prev,next',
center: 'title',
right: ''
},
viewRender: function(view, element) {
var newddddddd = moment($('#calendar').fullCalendar('getDate')).format("YYYY-MM-DD");
searchappointmentssss(newddddddd);
$("#dateselectedforapp").val(newddddddd + "T00:00");
},
eventClick: function(calEvent, jsEvent, view) {
$("#exampleModal2").modal('toggle');
$("#message-textm4").val(calEvent.id);
$("#message-textm444").val(calEvent.gicid);
$("#message-textm").val(calEvent.description);
$("#message-textm6").val(calEvent.visstatus);
$("#message-textm99").val(moment(calEvent.start).format("YYYY-MM-DD"));
$("#message-textm2").val(moment(calEvent.start).format("hh:mm"));
$("#message-textm3").val(moment(calEvent.end).format("hh:mm"));
// change the border color just for fun
$(this).css('border-color', 'red');
}
});
//document.execCommand("InsertImage", false, "upload/"+data);
//alert(data);
//$("#progressbar").hide();
//location.reload();
//$("#article").load("submitArticle.php");
//window.location.href = window.location.href;
},
error: function() {
alert(data);
}
});
}
Ps: Just putting this text cos stackoverflow was saying you question contains only code. this is not relevant :P

Assigning global variable to following Javascript

How can we make the var modal = $("#modal"); a global variable?
Where we have the modal variable in the following code, we need it to work, it currently doesn't,
var content = "Hello " + name + ", You have signed " + modal + " up to XYZ";
Many, many thanks!
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: 'prev,next today'
},
defaultDate: '2016-03-15',
events: [
{
title: 'Event',
start: '2016-03-26T11:00:00',
end: '2016-03-26T12:00:00',
},
],
eventClick: function(event) {
console.log(event)
// alert(event.start.format('MMMM Do YYYY'))
start = event.start.format('MMMM Do YYYY'),
end = event.end.format('MMMM Do YYYY'),
html = '<p>Starts: ' + start + '<p>';
html += '<p>Ends: ' + end + '<p>';
var modal = $("#modal");
modal.find(".modal-title").html(event.title);
modal.find('.modal-body').html(html)
modal.modal();
}
})
$("#contact_form").submit(function() {
var email = $("#email").val(); // get email field value
var name = $("#name").val(); // get name field value
var msg = $("#msg").val(); // get message field value
var content = "Hello " + name + ", You have signed " + modal + " up to XYZ";
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': 'api',
'message': {
'from_email': "email",
'text': "Hello ",
'from_name': "name",
'headers': {
'Reply-To': "email"
},
'subject': 'Confirmation - Sign Up',
'text': content,
'to': [{
'email': email,
'name': name,
'type': 'to'
}]
}
}
})
.done(function(response) {
alert('You have been signed up. Thank you!'); // show success message
$("#name").val(''); // reset field after successful submission
$("#email").val(''); // reset field after successful submission
$("#msg").val(''); // reset field after successful submission
})
.fail(function(response) {
alert('Error sending message.');
});
return false; // prevent page refresh
});
});
The simple solution for making value global is:
window.modal = "Value";
If you actually don't really need it but just want to store it in a way, where multiple functions will have an access to it you can create it in the scope of the function like:
(function(){
var modal = "value";
$.ajax({
success: function() {
console.log(modal);
}
})
})()

jQuery Form Validate not posting when using file upload

I've been using jQuery Validate plugin without problems for a while now, but not that I'm trying to use it with a file upload it does not work.
Im getting no post, and the page just reloads too quickly for me to see the "illegal" error that comes up.
The jQuery is as follows:
_validateModalForm = function(formID, modalShow){
var mesContainer = "#modal-message";
$("#" + formID).validate({
invalidHandler: function () { //display error alert on form submit
EMPGlobal.showAlert(mesContainer, '', 'danger', 'There was an error, please check the form, correct, and try again.' , '', '', '', 'warning');
},
submitHandler: function (form){
var formData = form;
formData = new FormData(formData);
console.log(formData);
$.ajax({
url: 'includes/pages/leads.php?',
//data: $(form).serialize(),
data: formData,
mimeType: "multipart/form-data",
type: "POST",
success: function (result) {
$.each(result, function(item, value){
if( (item == 'Success') || (item == 'Warning') ){
if(item == 'Success'){
var alertType = 'success';
} else {
var alertType = 'danger';
}
modalShow.modal('toggle');
EMPGlobal.showAlert('', '', 'success', value, '', '', '', alertType);
$('#lead-report-range').change(); //Reset the boxes
}
});
},
error: function (jqXHR, textStatus, errorThrown) {
returnMes = $.parseJSON(jqXHR.responseText);
message = 'A ' + jqXHR.status + ' ' + errorThrown + ' error occurred. <br /> <i>Message Details: ' + returnMes + '</i>';
EMPGlobal.showAlert(mesContainer, '', 'danger', message, '', '', '', 'warning', jqXHR.status);
},
});
return false;
}
});
$("#" + formID + " input[required='required']").each(function(){
$(this).rules( "add", {
required: true,
minlength: 2
});
});
};
It validates correctly, but just wont post over Ajax.
Any help on this one would be appreciated. I'm sure its something simple that I am missing.
Update
The error is as follows:
Uncaught TypeError: Illegal invocation
n.param.e # jquery-1.11.0.min.js:4
Wc # jquery-1.11.0.min.js:4
n.param # jquery-1.11.0.min.js:4
n.extend.ajax # jquery-1.11.0.min.js:4
$.validate.submitHandler # leads.js:157
d # VM16566:4(anonymous function) # VM16566:4
n.event.dispatch # jquery-1.11.0.min.js:3
n.event.add.r.handle # jquery-1.11.0.min.js:3
With the help of charlietfl managed to get this working.
_validateModalForm = function(formID, modalShow){
var mesContainer = "#modal-message";
$("#" + formID).validate({
invalidHandler: function () { //display error alert on form submit
EMPGlobal.showAlert(mesContainer, '', 'danger', 'There was an error, please check the form, correct, and try again.' , '', '', '', 'warning');
},
submitHandler: function (form){
var formData = new FormData($(form)[0]);
$.ajax({
url: 'includes/pages/leads.php?',
//data: $(form).serialize(),
data: formData,
type: "POST",
dataType: "json",
cache: false,
contentType: false,
processData: false,
success: function (result) {
$.each(result, function(item, value){
if( (item == 'Success') || (item == 'Warning') ){
if(item == 'Success'){
var alertType = 'success';
} else {
var alertType = 'danger';
}
modalShow.modal('toggle');
EMPGlobal.showAlert('', '', 'success', value, '', '', '', alertType);
$('#lead-report-range').change(); //Reset the boxes
}
});
},
error: function (jqXHR, textStatus, errorThrown) {
returnMes = $.parseJSON(jqXHR.responseText);
message = 'A ' + jqXHR.status + ' ' + errorThrown + ' error occured. <br /> <i>Message Details: ' + returnMes + '</i>';
EMPGlobal.showAlert(mesContainer, '', 'danger', message, '', '', '', 'warning', jqXHR.status);
},
});
return false;
}
});
};

How to get value from textfield to variables

Im using Mvc in C#.net and extjs. My question is
how to get value from textfield then set it to a variable and send email to multiple recipient.
This is my code for sending an email, and i want to get the values from the Extjs textfield id and set the id to a variable in sending. Then i want to send email to multiple recipient.
{
xtype: 'toolbar',
flex: 1,
dock: 'bottom',
ui: 'footer',
layout: {
pack: 'end',
type: 'hbox'
},
items: [{
xtype: 'button',
text: 'Send Email',
itemId: 'sen',
//iconCls: 'cancel'
handler: function() {
var rec = Ext.getCmp("activityGrid").getSelectionModel().selected()[0]
Ext.Ajax.request({
url: '/tblt_UAT_hr/generatePreview',
method: 'POST',
params: {
// id: Ext.get("Uath_Id").getValue(),
desc: rec.get("pc_desc"),
uat_date: rec.get("UAT_date"),
pcno: rec.get("pc_no"),
name: rec.get("name"),
stkid: rec.get("Stkhid")
},
success: function(resp) {
var result = Ext.decode(resp.responseText);
if (result.success) {
Ext.Ajax.request({
url: '/tblt_UAT_hr/SendEmailsTo',
method: 'POST',
params: {
from: null,
to: Ext.getCmp('to').getValue(),
subject: Ext.getCmp('subject').getValue(),
body: Ext.getCmp('bod').getValue(),
file: result.file
},
success: function(resp) {},
failure: function() {}
});
} else
mask.hide();
},
failure: function() {
mask.hide();
}
});
}
}, {
xtype: 'button',
text: 'Cancel',
itemId: 'can',
//iconCls: 'save'
}]
}]
public JsonResult SendEmailsTo(string from, string to, string subject, string body, string file) {
if (file != "" && file != null) {
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Credentials = new System.Net.NetworkCredential("ga.ojt.sunga#gmail.com", "1993doris");
smtpServer.Port = 587; // Gmail works on this port
string newfile = Server.MapPath("~/Content/pdf") + "\\" + file;
Attachment attachment = new Attachment(newfile);
mail.From = new MailAddress("ga.ojt.sunga#gmail.com");
//mail.To.Add(emailAdd);
foreach(var address in to.Split(new [] {
";"
}, StringSplitOptions.RemoveEmptyEntries)) {
mail.To.Add(address);
}
mail.Subject = subject;
mail.Body = body;
mail.Attachments.Add(attachment);
smtpServer.EnableSsl = true;
smtpServer.Send(e);
// return Content("email sent", "text/plain");
}
return Json(new {
success = true, msg = "success"
}, JsonRequestBehavior.AllowGet);
}
Find the text field, with ComponentQuery or otherwise, call getValue on it and add it to params of a request call. Pseudo code:
var field = Ext.ComponentQuery.query('#fieldItemId')[0];
params:{
yourField:field.getValue();
}

(#3) App must be on whitelist facebook

I'm trying to post a messsage to a wall using FB.api
My perms are: 'email, read_stream, publish_stream' and my code is:
FB.getLoginStatus(function(response){
if(response.session) {
var accessToken = response.session.access_token;
var tokenUrl = "https://graph.facebook.com/me/feed?access_token=" + accessToken + "&callback=?";
var shareUserId = document.getElementById("shareHidden").value;
var shareTxtAreaMsg = document.getElementById("shareTxtArea").value;
console.log("friends user Id: " + shareUserId + " & " + "message: " + shareTxtAreaMsg);
var data = {
message: "shareTxtAreaMsg",
display: 'iframe',
caption: "Caption",
name: "Name",
picture: 'http://someDomain.com/Dev/img/share-force-wall-img.jpg',
link: "http://www.facebook.com/pages/someapp/XXXXXXXXXXX?sk=app_XXXXXXXXXXXXXX", // Go here if user click the picture
description: "Description field",
actions: [{ name: 'action_links text!', link: 'some link' }],
}
console.log(accessToken);
FB.api(tokenUrl, 'post', data, function(response){
if (response)
{
//console.log(response);
if (response.error)
{
console.log(response.error.message);
}
else
{
if (response.id)
console.log("Posted as post_id "+response.id);
else if (response.post_id)
console.log("Posted as post_id "+response.post_id);
else
console.log("Unknown Error");
}
}
});
}
});
When when try to post the message I'm getting a "(#3) App must be on whitelist" returned. Why is this happening?
Try FB.api('/me/feed'... instead of tokenUrl because FB.api will automatically add the full url prefix.

Categories

Resources