So I am trying to setup a PhoneGap IOS and Parse.com Push notification app. I am using this plugin https://github.com/mgcrea/cordova-push-notification to register the device with apple and get back the device token. Now I need to save that data to the Installition class on my Parse. Problem is when I do a save it creates a new installation class.
var Installation = Parse.Object.extend("Installation");
var installation = new Installation();
installation.save({badge: status.pushBadge, deviceToken: status.deviceToken, deviceType: status.type, installationId: appID}, {
success: function(response){
alert("seccuees " + response);
},
error: function(error){
alert("error " + error.message);
}
});
I have also tried using a ajax call to the rest api and no go..
$.ajax({
type: 'GET',
headers: {'X-Parse-Application-Id':'miid','X-Parse-Rest-API-Key':'myid'},
url: "https://api.parse.com/1/installations",
data: {"deviceType": "ios", "deviceToken": "01234567890123456789", "channels": [""]},
contentType: "application/json",
success: function(response){
alert("Success " + response);
},
error: function(error){
alert("Error " + error.message);
}
});
Dont use "Installation" class. It will just create a new Installation object. To create Parse Installation object for Push notification, use "_Installation". Following is the way to do it.
var installation = new Parse.Object("_Installation");;
installation.save({ channels: ['channelName'], deviceType: "android", installationId: id}, {
success: function(response){
alert("success " + response);
},
error: function(error){
alert("error " + error.message);
}
});
Make sure type is 'POST' not 'Get' if you are updating data
$.ajax({
type: 'POST', // <============
headers: {'X-Parse-Application-Id':'miid','X-Parse-Rest-API-Key':'myid'},
url: "https://api.parse.com/1/installations",
data: {"deviceType": "ios", "deviceToken": "01234567890123456789", "channels": [""]},
contentType: "application/json",
success: function(response){
alert("Success " + response);
},
error: function(error){
alert("Error " + error.message);
}
});
Also could you provide more details on the error that is returned
Related
I have this simple login function and I want to add a preloader, after trying what's in their doc I can't make the preloader show any tips why? http://v2.framework7.io/docs/preloader.html source.
$$('.button-login').on('click', function (e) {
app.preloader.show();
var username = $("#username").val();
var password = $("#password").val();
if(username != '' && password !='' ){
app.request({
url: 'https://server/login',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
'username': username,
'password': password
}),
type: "POST",
dataType: "json",
crossDomain: true,
headers: {'Authorization' : 'Basic ' + btoa(username + ':' + password)},
error: function (data) {
app.preloader.hide();
app.dialog.alert('Invalid username or password!', 'Login Error');
},
success: function (data) {
app.dialog.alert('Welcome ' + username, 'Login Success');
localStorage.setItem('token', data.token);
localStorage.setItem('authorization', 'Basic' + btoa(username + ':' +password));
localStorage.setItem('username', username);
app.preloader.hide();
app.loginScreen.close();
Did you used var app = new Framework7(); to define app?
Is there some errors in console?
I made jsfiddle for you. Check it here.
If you want to hide preloader overlay after ajax call use dom7: $$('.preloader').hide();
Is there any possibility to call "WSDL" method in cloud code ?
for example, there is a "WSDL" web service and i want to check if there is an new data in it and if there is i want to send push notification to user. I got the logic, but i could not find any information about "WSDL" in parse.com documentation.
this didn't help:
Parse.Cloud.httpRequest({
url: 'https://services.rs.ge/WayBillService/WayBillService.asmx',
params: {
su : 'test1'
},
success: function(httpResponse) {
console.log(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
Sure you can, now, first we need to get a few things straight.
WSDL is just the definition of the services "Web Services Description Language"
You are talking SOAP here "Simple Object Access Protocol"
If you go to https://services.rs.ge/WayBillService/WayBillService.asmx in your browser, you will se a list of methods/SOAPActions that are available to you and if you click them, you will see an example of how to call the method.
For example, get_server_time, https://services.rs.ge/WayBillService/WayBillService.asmx?op=get_server_time
Example how to call get_server_time:
Parse.Cloud.job('soap', function(request, status) {
var Buffer = require('buffer').Buffer,
buffer = new Buffer(
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
' <soap12:Body>' +
' <get_server_time xmlns="http://tempuri.org/" />' +
' </soap12:Body>' +
'</soap12:Envelope>'
);
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://services.rs.ge/WayBillService/WayBillService.asmx',
headers: {
'Content-Type': 'text/xml; charset=utf-8'
},
body: buffer,
success: function(httpResponse) {
status.success(httpResponse.text);
},
error: function(httpResponse) {
status.error('Request failed with response code ' + httpResponse.status);
}
});
});
$.ajax({
type: "POST",
url: "ContactList.asmx/GetContacts",
data: "{'start':" + 1 + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$.mobile.showPageLoadingMsg();
console.log(msg.d);
},
error: function () {
$('[data-url="' + tempdataurl + '"] div[data-role="content"]').html("Error loading article. Please try web version.");
}
});
how can I send Muttiple paramater? I have 2 parameter start and count . please help.
Please try this code
data: {start: 1 ,count:5}
I am trying to load a jsonc feed, but I get an error:
"Jsonc is not enabled for this feed"
var url ='http://gdata.youtube.com/feeds/api/users/GoProCamera?v=2&alt=jsonc';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(response){
},
error:function(er){
console.log("Error: " , er);
},
});
Is there a way to check is jsonc is enabled?
I'm doing a simple post of a form using jquery. The problem is the $.ajax with POST is working but $.post is not. Look at the code below:
$.post(
{
url: url,
data: form.serialize(),
success: function (result) {
alert('startline posted');
}
});
And the working edition
$.ajax(
{
url: url,
type: "POST",
data: form.serialize(),
success: function (result) {
alert('startline posted');
},
error: function (jqXhr, textStatus, errorThrown) {
alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
}
});
Been debugging the $.post example until I just wanted to try out the $.ajax edition to get an error msg. But unfortunatly it just worked :)
How are the two methods different?
The parameter format for jQuery.post is url, data, callback, datatype. The parameter for jQuery.ajax is url, options or just options as you are using. In other words, the formatting on your $.post call is incorrect.
$.post( url, form.serialize())
.success( function (result) {
alert('startline posted');
});
try it
$.post takes multiple arguments, not one object like $.ajax. try it like this:
$.post(url, form.serialize(), function (result) {
alert('startline posted');
});
That's not how you use $.post
$.post('url/here.php', {
data: form.serialize()
}, function(result) {
alert('startline posted');
});