I am working on a phonegap app. I am facing some problem while passing value that I am getting from sqlite DB to jquery function.
I am passing a simple date variable to onclick = popUP("+date+");, but on the receiving end I am getting some different value. For example if date contains 2015-02-24 the popUP is receiving 1989. Here is my code:
//function will be called when process succeed
function resultSuccess(tx,response) {
for(var i=0;i<response.rows.length;i++){
date = response.rows.item(i).ARTI_DATE;
//alert("Title is : " +response.rows.item(i).ARTI_TITLE +"Date is : "+response.rows.item(i).ARTI_DATE+ "Des is : "+response.rows.item(i).ARTI_DESCRIP);
var margin = 10;
$("#routeContainer").append("<div style = 'margin-left: " + margin + "px;' class = 'test' id='d"+i+"' onclick='popUp("+date+")'><p style='padding-top: 90px;'><b>Thought for the..</b> <br/>Date: <span id='t"+i+"'>"+date+"</span> </p></div> ");
$('.test').css('background', 'url(img/thumbs/thought.jpg) no-repeat').height(100).width(100);
//$('.test').append($('<input></input>').attr('id','d'+i).attr('type','hidden').attr('value',date));
}
}
function popUp(d) {
alert("Value is " +d);
var db = window.openDatabase("DEVICEDATA", "1.0", "Device data", 200000); //will create database DEVICEDATA
db.transaction(SelectDesc, resultError, resultSuccess);
}
Related
I am creating admin panel in website and I am using firebase as a database in backend.I am able to display listing where onclick of accept status of listing get changed to 'accepted' but the thing is when status get change to accepted then listing in display should get filter and display only pending listing
pl.js
var firebaseheadingRef = firebase.database().ref().child("user");
function accept(userId) {
var nodeRef = firebase.database().ref("/user/" + userId + "/listing/status");
return nodeRef.set('accept');
}
function reject(userId) {
var nodeRef = firebase.database().ref("/user/" + userId + "/listing/status");
return nodeRef.set('reject');
}
firebaseheadingRef.on('child_added',datasnapshot=>{
var title= datasnapshot.child("listing").child("title").val();
var userid= datasnapshot.child("username").val();
var type= datasnapshot.child("listing").child("title").val();
var publisheddate= datasnapshot.child("listing").child("publish").val();
var expirydate= datasnapshot.child("listing").child("expire").val();
$("#tablebody").append("<tr><td>"+title+"</td><td>"+userid+"</td><td>"+type+"</td><td>"+publisheddate+"</td><td><button type=button id=accept onclick=accept('" + datasnapshot.key + "')>Accept</button><button type=button onclick=reject('" + datasnapshot.key + "')>Reject</button></td></tr>");
});
should display filter listing where status = pending
Database
You can use the orderByChild method along with the equalTo method to sort the children by status property
firebaseheadingRef.orderByChild("/listing/status").equalTo("pending")
.on('child_added',datasnapshot=>
{
//Enter your code here
});
Try changing the line
var firebaseheadingRef = firebase.database().ref().child("user");
to
var firebaseheadingRef = firebase.database().ref('/user');
I have a doGet(e) function in Google Script that writes to a spreadsheet, then returns a simple "success" message created with Content Service. My question is, is there a way to automatically close the tab/window created by this message? The user will be "approving" different items when they write to the spreadsheet, and it might get annoying to approve several items in a row using this function, then have to close each successive tab the function creates.
Here's the GS:
function doGet(e) {
var id = e.parameter.id;
var fundnumber = e.parameter.fundnumber;
var date = Utilities.formatDate(new Date(), "America/New_York", "MM/dd/yyyy");
var sh = SpreadsheetApp.openById("12jWGJWHCLoiLVoA0TlBQ0QgOMxBU9gVj9HQQveiNg0w").getSheetByName("Purchase Order Meta");
var data = sh.getDataRange().getValues();
for(n=0;n<data.length;++n){
if( data[n][1].toString().match(id)==id ){
data[n][8] = 'Approved by Linda on ' + date;
data[n][16] = 'Approved by Linda on ' + date + '. Awaiting order from Trish.';
data[n][13] = fundnumber
};
sh.getRange(1,1,data.length,data[0].length).setValues(data); // write back to the sheet
}
return ContentService.createTextOutput("success");
}
My understanding is that I have to return something either with Content Service or HTML Service in order to write a doGet. I've tried using HTML Service and add JS to the page to close the window, but it doesn't seem to work. :\
Using the HTMLService output, you can close a popup or HTML page by wrapping google.script.host.close() in a timeout function, like so:
setTimeout( function() { google.script.host.close(); }, 3000);
Change your return to:
var output = "<body><p>Success!</p><script>setTimeout( function() { google.script.host.close(); }, 3000);</script></body>"
return HtmlService.createHtmlOutput(output);
I am attempting to parse a JSON object located on another page on my website. The page is a hosted ecommerce platform, so I don't have server side access or control over certain elements on page.
I have some code that i'm using that is returning a strange error. I've tested this snippet (with a different URL of course) on another site running the same platform and it does it fact work.
website: http://www.falcontechjax.com
$.get('no-risk-diagnostic-2.aspx', function(data) {
var prodImgDetail = $.parseJSON($(data).find("#imginfo").html());
console.log(prodImgDetail);
});
On that page, there is a div container with the id "imginfo, that contains a JSON object.
<div id="imginfo" style="display:none;">{gallery : [{thumbnail : '/images/products/thumb/pipe.jpg', display : '/images/products/display/pipe.jpg', detailed : '/images/products/detail/pipe.jpg', alt : '', title : '' },{thumbnail : '/images/products/thumb/logo_printres1.jpg', display : '/images/products/display/logo_printres1.jpg', detailed : '/images/products/detail/logo_printres1.jpg', alt : 'PC Computer Diagnostic & Repair in Jacksonville FL', title : '' }],active : {thumbnail : '/images/products/thumb/pipe.jpg', display : '/images/products/display/pipe.jpg', detailed : '/images/products/detail/pipe.jpg', alt : '', title : '' }}</div>
The error I get when I run it is:
Uncaught SyntaxError: Unexpected token g jquery-1.7.2.min.js
update
Just to advise everyone, there is a version of this setup which works on another site on the same platform as mine:
Site: www.allvintagegames.com
$.get( "nes-adventures-of-bayou-billy.aspx", function( data ) {
var imgThumb, imgDisplay, imgDetailed, imgAlt, imgTitle;
var mycrap = $.parseJSON($(data).find("#imginfo").html());
//img information
$.each(mycrap.gallery, function(i, object) {
//alert(object);
imgThumb = object.thumbnail;
imgDisplay = object.display;
imgDetailed = object.detailed;
imgAlt = object.alt;
imgTitle = object.title;
});
//product information
var prodinf = $.parseJSON($(data).find("#iteminfo").html());
var infoLowprice = prodinf.lowprice;
var infoId = prodinf.id;
var infoName = prodinf.name;
var infoCaption = prodinf.caption;
var infoPrice = prodinf.price;
var infoSaleprice = prodinf.saleprice;
var infoCode = prodinf.code;
var infoOrderable = prodinf.orderable;
$("body").append("<img src='"+imgThumb+"' />");
$("body").append("<img src='"+imgDisplay+"' />");
$("body").append("<img src='"+imgDetailed+"' />");
$("body").append("<br />");
$("body").append(infoLowprice + "<br/>");
$("body").append(infoId + "<br/>");
$("body").append(infoName + "<br/>");
$("body").append(infoCaption + "<br/>");
$("body").append(infoPrice + "<br/>");
$("body").append(infoSaleprice + "<br/>");
$("body").append(infoCode + "<br/>");
$("body").append(infoOrderable + "<br/>");
});
This last example includes another object (#iteminfo contents) which is reference on the applicable page, just under the #imginfo div.
Any help figuring this out would be most appreciated!
As Felix King says, the JSON text is not properly formatted. You can see it if you try this in your debug console:
JSON.parse('{gallery: "foo"}')
and then this:
JSON.parse('{"gallery": "foo"}')
You'll see that when the key names are unquoted it doesn't work, which is what your JSON string has. One option is to instead use eval() to parse the string. Using eval is a terrible idea generally though, as it puts the code in your page at the mercy of whatever the server returns, which could be malicious code.
I have some experience using the SharePoint Client Object Model to retrieve text fields and URLs/images from lists in SP 2013. I'm currently trying to do something similar with a calendar. I have been able to successfully retrieve Title and Location fields without any issue, but the Start and End Time fields I am not able to retrieve. I cannot figure out what exactly the issue is. Additionally, I can read Created and Modified with no problems. Here is the relevant code:
function retrieveListItemsCal() {
var clientContextCal = new SP.ClientContext.get_current();
var oListCal = clientContextCal.get_web().get_lists().getByTitle('Calendar');
var camlQueryCal = new SP.CamlQuery.createAllItemsQuery();
AllItemsCal = oListCal.getItems(camlQueryCal);
clientContextCal.load(AllItemsCal);
clientContextCal.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededCal), Function.createDelegate(this, this.onQueryFailedCal));
}
function onQuerySucceededCal(sender, args) {
var listItemInfo = '';
var listItemEnumeratorCal = AllItemsCal.getEnumerator();
var htmlCal = '';
htmlCal+="<div id='CalHeader'>Upcoming Events</div>\
<div id='CalDivider'></div>\
<div id='CalContainer'>";
while(listItemEnumeratorCal.moveNext()) {
var oListItemCal = listItemEnumeratorCal.get_current();
/*htmlCal+="<div class='CalItem'>\
"oListItemCal.get_item('Start Time')"\
</div>";*/
alert(oListItemCal.get_item("Start Time").format("MMMM d, yyyy"));
}
htmlCal+="</div>";
$("#CalSpace").append(htmlCal);
}
function onQueryFailedCal(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
$(document).ready(function(){
SP.SOD.executeFunc("sp.js", "SP.ClientContext", retrieveListItemsCal);
});
And here is a screenshot of the list columns: http://i.imgur.com/8IK4KTO.png
I have resolved my issue. I ran the following PowerShell queries (found here http://techtrainingnotes.blogspot.com/2012/10/sharepointfinding-column-display-and.html):
$web = Get-SPWeb SiteUrl
$list = $web.Lists["Announcements"]
$list.fields | select Title, InternalName, Hidden, CanBeDeleted | sort title | ft -AutoSize
The internal names of the Start Time and End Time fields are EventDate and EndDate, respectively.
I do apologize if this is an easy fix, I'm a tad new to jquery. To start I don't think that it is my initial call that is messing up because if I put a simple alert function in than it will work fine onclick, basically when this <li> is clicked on, jquery trigers an ajax to php function sending the class of the <li> to a php script and back, opening an alert with the result. As far as I can tell it should be working, but again my knowledge is rather limited. Any change anyone can take a look at what I have and see if you can clean it up at all, currently nothing happens onclick, no errors even appear in the console. But I imagine that even my ajax call is wrong. Any ideas why nothing happens on click?
HTML:
<li title = "Previous Month" id = "changeMonthBack" class = "<?php echo date('n'); ?>"><img src="images/leftArrow.gif" width="54" height="45" alt="previous month"></li>
jQuery/javascript:
//javascript document
$(document).ready(function(){
//need to do an onclick for getting the new month(previous)
$(".changeMonthBack").click(function(){
function calendar(){
//set the id for php
var identifier = 1;
//get the class to use for month
var str = document.getElementById("changeMonthBack").class;
//get the month number
//if the month is 1, we obviously need it to be 12
if str == 1{
var month = 12;
}
else{
var month = str - 1;
}
$.post("redraw.php"),{
identifier: identifier,
month: month
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
};
})//end function 1
});
There are multiple problems with the script.
1. As Aesthete suggested the selector should be an id selector #changeMonthBack
2. You are creating a closure method called calendar but never called it
3. There were multiple syntax error (Use a javascript editor like spket)
You are creating a function called calendar but never calls it.
$(document).ready(function() {
// need to do an onclick for getting the new month(previous)
$("#changeMonthBack").click(function() {
// set the id for php
var identifier = 1;
// get the class to use for month
var str = parseInt($(this).attr('class'),10);
// get the month number
// if the month is 1, we obviously need it to be 12
if (str == 1) {
var month = 12;
} else {
var month = str - 1;
}
$.post("redraw.php", {
identifier : identifier,
month : month
},
function(data, status) {
alert("Data: " + data + "\nStatus: "
+ status);
});
});
});