Correct JSON format for GCM message
heres my JSON
var postData =
"{ \"registration_ids\": [ \"" +
pushNotificationState.RegistrationId + "\" ], "+
"\"data\": {\""+
pushNotificationState.NotificationData.NotificationData
+ "\"}";
registration Id and notification data are variables. I'm getting a 400
response from the GCM sever saying JSON is incorrect format. Can anyone
pick where I have gone wrong?
Cheers
Bubrig
Sunday, 1 September 2013
Mysterious behavior of ajax jquery request inside jquery tabs
Mysterious behavior of ajax jquery request inside jquery tabs
I have jquery tabs created and inside of a tab there is a form where at
the bottom of it, there is this button.
<button id="submitForm" onclick="formSubmition();">Submit</button>
Here are the headers
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script
src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="js/lib.js"></script>
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="css/style.css" />
formSubmition() exists in lib.js file and here is its code
function formSubmition(){
$recId = $("#recId").val();
$collectionDate = $("#collectionDate").val();
$collectorsName = $("#collectorsName").val();
$donorsName = $("#donorsName").val();
$sciName = $("#sciName").val();
$family = $("#family").val();
$comName = $("#comName").val();
$variety = $("#variety").val();
$area = $("#area").val();
$location = $("#location").val();
$altitude = $("#altitude").val();
$geoOrientation = $("#geoOrientation").val();
$geoCoordinates = $("#geoCoordinates").val();
$soilDescription = $("#soilDescription").val();
$habitatDescription = $("#habitatDescription").val();
$plantPopulation = $("#plantPopulation").val();
$photoDate = $("#photoDate").val();
$photoId = $("#photoId").val();
$photoComments = $("#photoComments").val();
$soilTaken = 0;
$seedQuantity = $("#seedQuantity").val();
$plantQuantity = $("#plantQuantity").val();
$graftQuantity = $("#graftQuantity").val();
$moreInfo = $("#moreInfo").val();
if($('#soilTaken').is(':checked')) // Checking if Checkbox
was checked.
$soilTaken = 1;
jQuery.ajax({
type: 'POST',
async: true,
url: 'classes/classController.php',
data: {method: "recNewPlant", recId: $recId, collectionDate:
$collectionDate, collectorsName: $collectorsName, donorsName:
$donorsName, sciName: $sciName, family: $family, comName:
$comName, variety: $variety, area: $area, location: $location,
altitude: $altitude, geoOrientation: $geoOrientation,
geoCoordinates: $geoCoordinates, soilDescription:
$soilDescription, habitatDescription: $habitatDescription,
plantPopulation: $plantPopulation, photoDate: $photoDate, photoId:
$photoId, photoComments: $photoComments, soilTaken: $soilTaken,
seedQuantity: $seedQuantity, plantQuantity: $plantQuantity,
graftQuantity: $graftQuantity, moreInfo: $moreInfo},
contentType: ('application/x-www-form-urlencoded'),
dataType: "json",
success : function(json){
if(json.status == '1'){
alert("Added!");
}else{
alert("Problema!");
}
}
});
}
The problem is that i have use this method so many times but this is the
first time that it behaves like this. What i mean. If i press the button ,
nothing happens at most of the time and some times (rare) in chromium only
(not in firefox) it sends a request to the server and it returns
"Problema" messagage.
I ve erased the cache of two browsers but nothing changed. Also i'm using
OWASP ZAP to see the traffic and indeed , doesn't send any POST request. I
thought that maybe the tabs cause that problem but i cannot find the why.
Here is the way i setup tabs:
$("#mainTabs").tabs();
I have jquery tabs created and inside of a tab there is a form where at
the bottom of it, there is this button.
<button id="submitForm" onclick="formSubmition();">Submit</button>
Here are the headers
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script
src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="js/lib.js"></script>
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="css/style.css" />
formSubmition() exists in lib.js file and here is its code
function formSubmition(){
$recId = $("#recId").val();
$collectionDate = $("#collectionDate").val();
$collectorsName = $("#collectorsName").val();
$donorsName = $("#donorsName").val();
$sciName = $("#sciName").val();
$family = $("#family").val();
$comName = $("#comName").val();
$variety = $("#variety").val();
$area = $("#area").val();
$location = $("#location").val();
$altitude = $("#altitude").val();
$geoOrientation = $("#geoOrientation").val();
$geoCoordinates = $("#geoCoordinates").val();
$soilDescription = $("#soilDescription").val();
$habitatDescription = $("#habitatDescription").val();
$plantPopulation = $("#plantPopulation").val();
$photoDate = $("#photoDate").val();
$photoId = $("#photoId").val();
$photoComments = $("#photoComments").val();
$soilTaken = 0;
$seedQuantity = $("#seedQuantity").val();
$plantQuantity = $("#plantQuantity").val();
$graftQuantity = $("#graftQuantity").val();
$moreInfo = $("#moreInfo").val();
if($('#soilTaken').is(':checked')) // Checking if Checkbox
was checked.
$soilTaken = 1;
jQuery.ajax({
type: 'POST',
async: true,
url: 'classes/classController.php',
data: {method: "recNewPlant", recId: $recId, collectionDate:
$collectionDate, collectorsName: $collectorsName, donorsName:
$donorsName, sciName: $sciName, family: $family, comName:
$comName, variety: $variety, area: $area, location: $location,
altitude: $altitude, geoOrientation: $geoOrientation,
geoCoordinates: $geoCoordinates, soilDescription:
$soilDescription, habitatDescription: $habitatDescription,
plantPopulation: $plantPopulation, photoDate: $photoDate, photoId:
$photoId, photoComments: $photoComments, soilTaken: $soilTaken,
seedQuantity: $seedQuantity, plantQuantity: $plantQuantity,
graftQuantity: $graftQuantity, moreInfo: $moreInfo},
contentType: ('application/x-www-form-urlencoded'),
dataType: "json",
success : function(json){
if(json.status == '1'){
alert("Added!");
}else{
alert("Problema!");
}
}
});
}
The problem is that i have use this method so many times but this is the
first time that it behaves like this. What i mean. If i press the button ,
nothing happens at most of the time and some times (rare) in chromium only
(not in firefox) it sends a request to the server and it returns
"Problema" messagage.
I ve erased the cache of two browsers but nothing changed. Also i'm using
OWASP ZAP to see the traffic and indeed , doesn't send any POST request. I
thought that maybe the tabs cause that problem but i cannot find the why.
Here is the way i setup tabs:
$("#mainTabs").tabs();
Pass QueryOver query as parameter to then execute (nhibernate)
Pass QueryOver query as parameter to then execute (nhibernate)
I have sort of a DOA class where I have my insert, update delete's etc
centralized and I also want to have the QueryOver method there. The method
will create the session etc and All I want to give it from a higher class
is the query.
Logically I would be something like this I guess...
public object QueryOver<T>(IQueryOver query)
{
using (ISession session = SessionManager.OpenSession())
{
return session.QueryOver<T>(???
}
}
Any Ideas? Or this having this 'Ópen session' centralized a bad practice?
I have sort of a DOA class where I have my insert, update delete's etc
centralized and I also want to have the QueryOver method there. The method
will create the session etc and All I want to give it from a higher class
is the query.
Logically I would be something like this I guess...
public object QueryOver<T>(IQueryOver query)
{
using (ISession session = SessionManager.OpenSession())
{
return session.QueryOver<T>(???
}
}
Any Ideas? Or this having this 'Ópen session' centralized a bad practice?
Saturday, 31 August 2013
QtCreator GUI open text file
QtCreator GUI open text file
I made a push button that will browse and get a textfile. But I need to
open it in a new window to check if the content of the textfile is
correct. How do I do this?
Also, I would like to have a line edit right next to the button that shows
which file I'm looking at. In other words, the directory of the file that
is opened through the button.
Currently, this is what I have:
void MainWindow::on_fileButton_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text
File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file1);
while(!in.atEnd()){
QString line = in.readLine();
}
}
I made a push button that will browse and get a textfile. But I need to
open it in a new window to check if the content of the textfile is
correct. How do I do this?
Also, I would like to have a line edit right next to the button that shows
which file I'm looking at. In other words, the directory of the file that
is opened through the button.
Currently, this is what I have:
void MainWindow::on_fileButton_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text
File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file1);
while(!in.atEnd()){
QString line = in.readLine();
}
}
How to remove a directory from git index but not working tree directory?
How to remove a directory from git index but not working tree directory?
In case I messed up my definitions, I want git to stop tracking a folder,
but I want that folder to remain on my local machine.
I tried the following:
[ubuntu@ip-172-31-10-215:~/bitstarter]$cat .gitignore
# Heroku environmental variables, including API keys.
# https://devcenter.heroku.com/articles/config-vars
.env
# npm packages
node_modules
# Mac
.DS_Store
# Emacs
*~
[ubuntu@ip-172-31-10-215:~/bitstarter]$git status
# On branch temp
nothing to commit (working directory clean)
[ubuntu@ip-172-31-10-215:~/bitstarter]$git rm -r --cached node_modules
fatal: pathspec 'node_modules' did not match any files
Note worthy that I modified node_modules, committed changes, added
node_modules to .gitignore, committed THAT change, and now I have a
"clean" working directory.
In case I messed up my definitions, I want git to stop tracking a folder,
but I want that folder to remain on my local machine.
I tried the following:
[ubuntu@ip-172-31-10-215:~/bitstarter]$cat .gitignore
# Heroku environmental variables, including API keys.
# https://devcenter.heroku.com/articles/config-vars
.env
# npm packages
node_modules
# Mac
.DS_Store
# Emacs
*~
[ubuntu@ip-172-31-10-215:~/bitstarter]$git status
# On branch temp
nothing to commit (working directory clean)
[ubuntu@ip-172-31-10-215:~/bitstarter]$git rm -r --cached node_modules
fatal: pathspec 'node_modules' did not match any files
Note worthy that I modified node_modules, committed changes, added
node_modules to .gitignore, committed THAT change, and now I have a
"clean" working directory.
How can I make an interface instance method accept arguments of the same class only, really?
How can I make an interface instance method accept arguments of the same
class only, really?
This SO discussion proposes the following idiom:
public interface IComparable<T extends IComparable<T>> {
public int compare(T t);
}
which then allows:
public class Foo implements IComparable<Foo> {
public int compare(Foo foo) {
return 0;
}
}
However, this idiom allows more than just the above as the following code
compiles as well:
class A implements IComparable<A> {
public int compare(A a) {return 0;}
}
public class Foo implements IComparable<A> {
public int compare(A a) {
return 0;
}
}
Therefore (unless I've misunderstood something) the original idiom doesn't
really buy anything more compared to the far less dramatic:
public interface IComparesWith<T> {
public int compare(T t);
}
public class A implements IComparesWith<A> {
public int compare(A a) {...}
}
So, is there a way to actually declare an interface such that whatever
class declares to implement it has a method to compare with objects of its
own class, without any loopholes such the one above?
I obviously could't post the above as a comment hence I created a new post.
class only, really?
This SO discussion proposes the following idiom:
public interface IComparable<T extends IComparable<T>> {
public int compare(T t);
}
which then allows:
public class Foo implements IComparable<Foo> {
public int compare(Foo foo) {
return 0;
}
}
However, this idiom allows more than just the above as the following code
compiles as well:
class A implements IComparable<A> {
public int compare(A a) {return 0;}
}
public class Foo implements IComparable<A> {
public int compare(A a) {
return 0;
}
}
Therefore (unless I've misunderstood something) the original idiom doesn't
really buy anything more compared to the far less dramatic:
public interface IComparesWith<T> {
public int compare(T t);
}
public class A implements IComparesWith<A> {
public int compare(A a) {...}
}
So, is there a way to actually declare an interface such that whatever
class declares to implement it has a method to compare with objects of its
own class, without any loopholes such the one above?
I obviously could't post the above as a comment hence I created a new post.
View not attached to window manager exception even isfinishing is called
View not attached to window manager exception even isfinishing is called
I keep getting this exception "View not attached to window manager"
reports from ACRA and it is always happening around my dialog.dismiss() in
my async task. I have searched SO and I added the (!isFinishing())
condition but I still get it. Can you please tell me how I can solve it?
Here is a sample code where it happens
private class MyAsyncTask extends AsyncTask<String, Void, Void> {
private ProgressDialog dialog;
private PropertyTask asyncTask;
public MyAsyncTask (PropertyTask task){
this.asyncTask = task;
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(ListTasksActivity.this, "Please
wait..", "working..", true);
}
@Override
protected Void doInBackground(String... params) {
//Some DB work here
return null;
}
@Override
protected void onPostExecute(Void result) {
if(!isFinishing()){
dialog.dismiss(); <-------- Problem happens
}
}
}
I keep getting this exception "View not attached to window manager"
reports from ACRA and it is always happening around my dialog.dismiss() in
my async task. I have searched SO and I added the (!isFinishing())
condition but I still get it. Can you please tell me how I can solve it?
Here is a sample code where it happens
private class MyAsyncTask extends AsyncTask<String, Void, Void> {
private ProgressDialog dialog;
private PropertyTask asyncTask;
public MyAsyncTask (PropertyTask task){
this.asyncTask = task;
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(ListTasksActivity.this, "Please
wait..", "working..", true);
}
@Override
protected Void doInBackground(String... params) {
//Some DB work here
return null;
}
@Override
protected void onPostExecute(Void result) {
if(!isFinishing()){
dialog.dismiss(); <-------- Problem happens
}
}
}
Subscribe to:
Posts (Atom)