Parameter name "id" in $.post doesn't work - post

I have the following code that I am using to post information to update an event. When I comment out the "id" param, the post succeeds and I receive information back from the server. However, when "id" is not commented out, nothing is sent.
var user = localStorage["user"];
var pw = localStorage["pw"];
var org = localStorage["org"];
var eventid = localStorage["eventid"];
$(function () {
$("#submit").click(function () {
if ($("#cancelled:checked")){
cancel = "on";
}else {
cancel = "";
}
$.post(
"/App/SetNewEvent/default.asp",
{
user: user,
key: pw,
org: org,
id: eventid,
playdate: $("#playdate").val(),
start: $("#start").val(),
finish: $("#finish").val(),
location: $("#facilityid").val(),
tournament: $("#type").val(),
cancelled: cancel,
team: $("#teamid").val(),
homeopponent: $("#homeopponentid").val(),
schednote: $("#note").val()
},
function (response) {
console.log(response);
}
);
});
})

Related

Parse Push Notification Cloud Code Error?

UPDATE: I was getting this error because of a bug that Parse-Server 2.2.17 has. I fixed it by going back to 2.2.16.
Does anyone know why I am getting this error? Here is my cloud code:
`Parse.Cloud.define("Messages", function(request, response) {
var pushQuery = new Parse.Query(Parse.Installation);
Parse.Push.send({
where: pushQuery,
data: {
alert: "New Event Added",
sound: "default"
}
},{
success: function(){
console.log("Push Sent!")
},
error: function (error) {
console.log(error)
},
useMasterKey: true
});
});`
Here is the error I am getting:
And then this is how I am calling the code: `PFCloud.callFunctionInBackground("Messages", withParameters: nil) { (object, error) in
if error == nil {
print("Success!")
} else {
print(error)
}
}
index.js:
`
Can you please try the following code:
var query = new Parse.Query(Parse.Installation);
// query condition (where equal to .. etc.)
var payload = {
alert: "New Event Added",
sound: "default"
};
Parse.Push.send({
where: query, // Set our Installation query
data: payload
}, {
success: function () {
},
error: function (error) {
// Handle error
}
});
Please notice that i remove the useMasterKey if you want to add useMasterKey you need to insert it inside closures but for me it's works without the useMasterKey
the useMasterKeyVersion should look like the following:
Parse.Push.send({
where: query, // Set our Installation query
data: payload
},
{
useMasterKey: true
},
{
success: function () {
},
error: function (error) {
// Handle error
}
});
The promises version (according to best practices):
Parse.Push.send({where: query,data: payload})
.then(function(){
// success
},function(error){
// error ..
});
Update
by looking at your index.js file it looks like you didn't add the facebook oauth to your 3-party authentication logins.
so you will need to add the following:
oauth: {
facebook: {
appIds: "FACEBOOK APP ID"
}
}
below your emailAdapter config and inside "FACEBOOK APP ID" put the app ID that you created in facebook developers
in main.js put this code
// SEND PUSH NOTIFICATION
Parse.Cloud.define("push", function(request, response) {
var user = request.user;
var params = request.params;
var someKey = params.someKey
var data = params.data
var recipientUser = new Parse.User();
recipientUser.id = someKey;
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("userID", someKey);
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: data
}, { success: function() {
console.log("#### PUSH OK");
}, error: function(error) {
console.log("#### PUSH ERROR" + error.message);
}, useMasterKey: true});
response.success('success');
});
// SEND PUSH NOTIFICATION FOR ANDROID
Parse.Cloud.define("pushAndroid", function(request, response) {
var user = request.user;
var params = request.params;
var someKey = params.someKey
var data = params.data
var recipientUser = new Parse.User();
recipientUser.id = someKey;
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("userID", someKey);
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {
alert: data
}
}, { success: function() {
console.log("#### PUSH OK");
}, error: function(error) {
console.log("#### PUSH ERROR" + error.message);
}, useMasterKey: true});
response.success('success');
});
in xcode project do like that to send push notification
// Send Push notification
let pushStr = "#\(PFUser.current()![USER_USERNAME]!) | \n\(self.lastMessageStr)"
let data = [ "badge" : "Increment",
"alert" : pushStr,
"sound" : "bingbong.aiff",
] as [String : Any]
let request = [
"someKey" : self.userObj.objectId!,
"data" : data
] as [String : Any]
PFCloud.callFunction(inBackground: "push", withParameters: request as [String : Any], block: { (results, error) in
if error == nil {
print ("\nPUSH SENT TO: \(self.userObj[USER_USERNAME]!)\nMESSAGE: \(pushStr)\n")
} else {
print ("\(error!.localizedDescription)")
}
})

Cloudboost logout function

When I try to log out the current user of my app I get this message : TypeError: CB.CloudUser.current.logOut is not a function
Here is my code :
$scope.logout = function() {
CB.CloudUser.current.logOut({
success: function(user) {
//log out successfull
var currentUser = user;
$timeout(function() {
$scope.userConnected = false;
document.getElementById("body-container").className = "hold-transition login-page";
});
},
error: function(err) {
//Error occured in user registration.
}
});
Thank you for your help.
Here is what I have in CB.CloudUser.current:
CB.CloudObject {document: Object}
ACL: (...)
createdAt: (...)
document: Object
ACL: CB.ACL
_id: "OUVrZf9T"
_tableName: "User"
_type: "custom"
_version: 1
createdAt: "2016-02-27T21:15:09.013Z"
email: ""
expires: null
password: ""
updatedAt: "2016-02-27T21:15:27.403Z"
username: "malignois"
__proto__: Object
expires: (...)
id: (...)
updatedAt: (...)
__proto__: CB.CloudObject
I know this is old but this is what works for me. I am using Ionic 2, but the syntax should be the same. Hope this helps.
CB.CloudUser.getCurrentUser({
success: function (user) {
// Success getting current user
user.logOut({
success: function () {
// Success logging out
},
error: function () {
// Error logging out
}
});
},
error: function () {
// Error getting current user
}
});

Error in angular Controller

Below is my code in AngularJS. i have created controller but i am getting error :
Error: [ng:areq] Argument 'forgetController' is not a function, got
undefined
app.controller("forgetController", function ($scope, forgetService) {
$scope.OperType = 1;
// 1 MEANS NEW ENTRY
GetAllUserRecords();
function GetAllUserRecords() {
debugger;
var promiseGet = userService.GetUserRecords();
promiseGet.then(function (p1) { $scope.User = p1.data }, function (err) {
console.log("Error");
});
}
$scope.submit = function () {
debugger;
var user = {
FirstName: $scope.FirstName,
LastName: $scope.LastName,
Email: $scope.Email,
Password: $scope.Password,
Phone: $scope.Phone,
Postcode: $scope.Postcode,
Address: $scope.Address,
Street: $scope.Street,
Town: $scope.Town,
CreateDate: new Date()
};
if ($scope.OperType === 1) {
var promisePost = userService.AddUser(user);
promisePost.then(function (p1) {
GetAllUserRecords();
alert("New Record Inserted");
$("#addUserTable").css('display', 'none');
clearClientDetail();
}, function (err) {
console.log("Error");
});
}
}
function clearClientDetail() {
$("#FirstName").val('');
$("#LastName").val('');
$("#Email").val('');
$("#Password").val('');
$("#Phone").val('');
$("#Postcode").val('');
$("#Address").val('');
$("#Street").val('');
$("#Town").val('');
}
});
i am stuck over here, i google everything but i do not get any result.
Add this line of code just above controller code
var app = angular.module('myapp', ['forgetService']);

gapi.auth.signOut(); not working I'm lost

Below is the code I am using to login with google. I have an element on login.php with id authorize-button. When clicked it logs in just fine.
I have a logout link in my header file. When I click the logout it calls gapi.auth.signOut(); then it destroys session and redirects back to login.php
This happens as far as I can tell but then it just logs the user right back into our site with google. This is a pain as some of our users switch from google to facebook logins.
Thanks in advance for any help.
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth, 1);
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult && !authResult.error) {
//authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
//authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
return false;
}
function signOut() {
gapi.auth.signOut();
}
function makeApiCall() {
gapi.client.load('oauth2', 'v2', function() {
var request = gapi.client.oauth2.userinfo.get();
request.execute(function(logResponse) {
var myJSON = {
"myFirstName": logResponse.given_name,
"myLastName": logResponse.family_name,
"name": logResponse.name,
"socialEmailAddress": logResponse.email
};
gapi.client.load('plus', 'v1', function() {
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(logResponse2) {
//alert(JSON.stringify(logResponse));
myJSON['profilePicture'] = logResponse2.image.url;
myJSON['socialId'] = logResponse2.id;
//alert(JSON.stringify(myJSON));
$.ajax({
type: "POST",
url: "includes/login-ajax.php",
data: "function=googleLogin&data=" + JSON.stringify(myJSON),
dataType: "html",
success: function(msg) {
if (msg == 1) {
//window.location = "settings.php";
}
}
});
});
});
});
});
}
Make sure you have set your cookie-policy to a value other than none in your sign-in button code. For example:
function handleAuthClick(event) {
gapi.auth.authorize(
{
client_id: clientId,
scope: scopes,
immediate: false,
cookie_policy: 'single_host_origin'
},
handleAuthResult);
return false;
}
Note that sign out will not work if you are running from localhost.
Weird issue, but solved my problem by rendering the signin button (hidden) even if the user is authenticated.
See full question/answer here https://stackoverflow.com/a/19356354/353985
I came across the same issue today. I have search for solution the whole. The only reliable solution that worked for me is through revoke as explained here
I stored access_token in session which is needed during revoke
Below is my code you may find it useful
function logout() {
var access_token = $('#<%=accessTok.ClientID %>').val();
var provider = $('#<%=provider.ClientID %>').val();
if (access_token && provider) {
if (provider == 'GPLUS') {
var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' +
access_token;
// Perform an asynchronous GET request.
$.ajax({
type: 'GET',
url: revokeUrl,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function (nullResponse) {
// Do something now that user is disconnected
// The response is always undefined.
},
error: function (e) {
// Handle the error
// console.log(e);
// You could point users to manually disconnect if unsuccessful
// https://plus.google.com/apps
}
});
}
else if (provider == 'FB') {
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
FB.logout();
}
});
}
} else {
}
}

Checking if all data has been returned from server in Knockout

I am displaying data from the user on the user page and i would like to notify the user once all the data has been loaded and there is no more data to retrieve from the server using knockout.
Knockout script
$.views.Roster.GetPage = function ( pageNumber) {
$.grain.Ajax.Get({
Url: Views.Roster.Properties.Url,
DataToSubmit: { pageNumber: pageNumber, id: Views.Roster.Properties.Id },
DataType: "json",
OnSuccess: function (data, status, jqXHR) {
$.views.Roster.RosterViewModel.AddUsers(data);
},
OnError: function (jqXHR, status, errorThrown) {
var _response = $.parseJSON(jqXHR.responseText);
$.pnotify({ title:_response.title, text: _response.Message, type: _response.TypeString});
}
});
};
$.views.Roster.ViewModel = {
RosterUsers: ko.observableArray([]),
TotalRoster: null,
CurrentPage: ko.observable(1)
};
$.views.Roster.BindModel = function (data) {
var self = $.views.Roster.ViewModel;
$.views.Roster.ViewModel.TotalRoster = ko.computed(function () {
return self.RosterUsers().length;
});
$.views.Roster.RosterViewModel.AddUsers(data);
ko.applyBindings($.views.Roster.ViewModel);
}
Next = function () {
var _page = $.views.Roster.ViewModel.CurrentPage() + 1;
$.views.Roster.ViewModel.CurrentPage(_page);
$.views.Roster.GetPage(_page);
};
$.views.Roster.RosterViewModel = function (data) {
$.views.Roster.RosterViewModel.AddUsers(data);
};
$.views.Roster.RosterViewModel.AddUsers = function (data) {
$.each(data, function (index, value) {
$.views.Roster.RosterViewModel.PushUser(value);
});
};
$.views.Roster.RosterViewModel.PushUser = function (user) {
$.views.Roster.ViewModel.RosterUsers.push(new $.views.Roster.UserViewModel(user));
};
When you say 'once all the data has been loaded', I assume you mean when the GetPage method finishes loading a single page of users, as that is the only data loading that I see in the code above. Here is one way you can do it:
First, create an observable somewhere that you can bind to to tell the user if data is loading
$.views.Roster.ViewModel = {
RosterUsers: ko.observableArray([]),
TotalRoster: null,
CurrentPage: ko.observable(1),
DataIsLoading: ko.observable(false)
};
And add some markup that shows something in the UI when data is loading
<div data-bind="visible:DataIsLoading">Data is Loading, please wait...</div>
Then set DataIsLoading before you make the ajax call, then reset it when the call is done
$.views.Roster.GetPage = function ( pageNumber) {
$.views.Roster.ViewModel.DataIsLoading(true); // Add this!
$.grain.Ajax.Get({
Url: Views.Roster.Properties.Url,
DataToSubmit: { pageNumber: pageNumber, id: Views.Roster.Properties.Id },
DataType: "json",
OnSuccess: function (data, status, jqXHR) {
$.views.Roster.RosterViewModel.AddUsers(data);
$.views.Roster.ViewModel.DataIsLoading(false); // Add this!
},
OnError: function (jqXHR, status, errorThrown) {
var _response = $.parseJSON(jqXHR.responseText);
$.pnotify({ title:_response.title, text: _response.Message, type: _response.TypeString});
$.views.Roster.ViewModel.DataIsLoading(false); // Add this!
}
});
};

Resources