Created a fake train schedule to try to learn firebase. communication between page and server is good however I want the times to update on the client side web page every minute but only the times. The times are displayed in a table.
//pull from database and prints to screen/html
trainDataBase.ref().on("child_added", function (childSnapshot) {
console.log("childSnapshot", childSnapshot.val());
// Store everything into a variable.
var trainName = childSnapshot.val().tname;
var destination = childSnapshot.val().dest;
var firstTrainTime = childSnapshot.val().firstTime;
var frequency = childSnapshot.val().freq;
// Minute Until Train
var tMinutesTillTrain = frequency - tRemainder;
console.log("MINUTES TILL TRAIN: " + tMinutesTillTrain);
// Next Train
var nextTrain = moment().add(tMinutesTillTrain, "minutes");
console.log("ARRIVAL TIME: " + moment(nextTrain).format("hh:mm"));
nextTrainConverted = moment(nextTrain).format("hh:mm A")
$("#train-table > tbody").append("<tr><td>" + trainName + "</td><td>" + destination + "</td><td>" + frequency + " Minutes" + "</td><td>" + tMinutesTillTrain + " Minutes" + "</td><td>" + nextTrainConverted + "</td><td>" + '<button class="update">Update</button>' + "</td></td>" + "</td><td>" + '<button class="remove">Remove</button>' + "</td></tr>");
});
Just want to update the train times and minutes till next train.
Related
I am making a website with Python backend using flask and sqlite3. Most of my program is working, but I have a flask function that is called on a button click and executed in parallel with ajax request. It has 3 lines of sqlite updating 3 different table, but only the last one is making changes in the table. here is the function:
#app.route('/add_slot',methods=["POST","GET"])
def add_slot():
conn = sqlite3.connect("example.db")
sem = request.json["sem"]
sec = request.json["sec"]
sub = request.json["sub"]
teacher = request.json["teacher"]
room_no = request.json["room_no"]
time = int(request.json["time"])
day = int(request.json["day"])
cur = conn.execute("select assign_slot from teacher where teacher_name = '" + teacher + "'")
slots = cur.fetchall()[0][0]
slots = slots[:(day-1)*10 + time-1] + "1" + slots[(day-1)*10 + time:]
cur = conn.execute("select availability from room where room_no = " + room_no)
avail = cur.fetchall()[0][0]
avail = avail[:(day-1)*10 + time-1] + "0" + avail[(day-1)*10 + time:]
conn.execute("update room set availability = '" + avail + "' where room_no = " + room_no)
conn.execute("update teacher set assign_slot = '" + slots + "' where teacher_name = '" + teacher + "'")
conn.execute("update tt set subject_name = '" + sub + "', teacher_name = '" + teacher + "', room_no = " + room_no + " where semester = " + sem + " and section = '" + sec + "' and time_ = " + str(time) + " and day = " + str(day))
conn.commit()
conn.close()
return
And the JS code calling the function is:
The last sql line is working, which updates the table tt, but others don't. I tried executing the sql statements independently on the powershell, putting the same values for the variables as passed when the function is called, and they work in the powershell. So, why are they not working in the program?
function send_data(){
$.ajax({
type:'POST',
url:'/add_slot' ,
contentType: 'application/json;charset=UTF-8',
data : {'sec':document.getElementById("sec").value,'sem':document.getElementById("sem").value,'sub':document.getElementById("sub").value,'day':document.getElementById("sel1").value,'time':document.getElementById("sel2").value,'teacher':document.getElementById("sel3").value,'room_no':document.getElementById("sel_r").value}
});
close_popup();
initial_processing();
}
I'm new to this. And have a code. HTML form that has 4 Checkboxes
The result goes into a G-spreadsheet. From the Sheet I want the checked boxes values to polulate a Calendar event. Now it works but I get all the Checkboxes values in the calendar. Not only the ones that are checked.
function appendData(data){
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Records");
Logger.log(data)
// Lägg till rad i spreadsheet
ws.appendRow([data.name, data.email, data.cuser, data.lastday, data.telenor, data.comment, data.company, data.costacc, data.laptop, data.ipad, data.printer, data.router]);
// Create data for event
var title = data.name + " börjar sin anställning på Roche"
var date = new Date(data.lastday)
var description = "<b>Mobil + Abonnemang:</b>\n" + data.telenor + "\n\n" +
"<b>Bolag:</b>\n" + data.company + "\n\n" +
"<b>Övrig utrustning:</b>\n" + data.laptop + ", " + data.ipad + ", " + data.printer + ", " + data.router
"<b>Kopiera rättigheter från:</b>\n" + data.cuser + "\n\n" +
"<b>Övriga kommentarer:</b>\n" +
data.comment
I am working with Square POS API and have successfully sent a request to the android app via a mobile web app. The app opens, displays the correct price, accepts payment and returns to the callback URL.
I have read over the documentation a few times and may be missing it but is there a way I can add a Unique ID that is sent to the app and returned to the callback page so I can update the correct line item in the database?
possibly something like:
"l.com.squareup.pos.UNIQUE_ID=" + unique_id + ";" +
var posUrl =
"intent:#Intent;" +
"action=com.squareup.pos.action.CHARGE;" +
"package=com.squareup;" +
"S.com.squareup.pos.WEB_CALLBACK_URI=" + callbackUrl + ";" +
"S.com.squareup.pos.CLIENT_ID=" + applicationId + ";" +
"S.com.squareup.pos.API_VERSION=" + sdkVersion + ";" +
"i.com.squareup.pos.TOTAL_AMOUNT=" + transactionTotal + ";" +
"S.com.squareup.pos.CURRENCY_CODE=" + currencyCode + ";" +
"S.com.squareup.pos.TENDER_TYPES=" + tenderTypes + ";" +
"l.com.squareup.pos.AUTO_RETURN_TIMEOUT_MS=" + callbacktime + ";" +
"l.com.squareup.pos.UNIQUE_ID=" + unique_id + ";" +
"end";
Whenever I click on my button to fire the below query it keeps on appending to the existing table.Is there any way I can refresh the page for every button click.
function submitClick() {
$(document).ready(function () {
const rootRef = firebase.database().ref().child("Orders/");
const query = rootRef.orderByChild('Session').equalTo('VEG');
query.on("child_added", snap => {
var user_id = snap.child("User id").val();
var name = snap.child("Username").val().toUpperCase();
$("#table_body").append("<tr><td>" + user_id + "</td> <td>" + name + "</td> <td>" + email +
"</td><td>" + address + "</td><td>" + dabba_type + "</td><td>" + session + "</td><td>" + start +
"</td><td>" + end + "</td><td>" + phone + "</td><td>" + "Rs " + price + "</td><td>" + feedback + "</td></tr>");
});
});
}
try adding $("#table_body").empty() at the start of the function
create the html into variable and then add to the body
var html = "<tr><td>" + user_id + "</td> <td>" + name + "</td> <td>" + email +
"</td><td>" + address + "</td><td>" + dabba_type + "</td><td>" + session + " </td><td>" + start +
"</td><td>" + end + "</td><td>" + phone + "</td><td>" + "Rs " + price + "</td><td>" + feedback + "</td></tr>";
$("#table_body").html(html);
I can't understand. You can use ajax to reload page or datatables be the best way for refreshing table with out page reload. If you want just reload page then use
location.reload();
In my form I have a total field which is the sum of several checkboxes. When it reaches 21 total page one must be created. below the code, which worked well in another case and this time it gives me a syntax error. someone there you an idea ??
Thank you in advance
this.getField("TOTAL").value =
this.getField("P6eval_competences.manageriales.0").value +
this.getField("P6eval_competences.manageriales.1").value +
this.getField("P6eval_competences.manageriales.2").value +
this.getField("P6eval_competences.manageriales.3").value +
this.getField("P6eval_competences.manageriales.4").value +
this.getField("P6eval_competences.manageriales.5").value +
this.getField("P6eval_competences.manageriales.6").value +
this.getField("P6eval_competences.manageriales.7").value +
this.getField("P6eval_competences.manageriales.8").value +
this.getField("P6eval_competences.manageriales.9").value +
this.getField("P6eval_competences.manageriales.10").value +
this.getField("P6eval_competences.manageriales.11").value +
this.getField("P6eval_competences.manageriales.12").value +
this.getField("P6eval_competences.manageriales.13").value +
this.getField("P6eval_competences.manageriales.14").value +
this.getField("P6eval_competences.manageriales.15").value +
this.getField("P6eval_competences.manageriales.16").value +
this.getField("P6eval_competences.manageriales.17").value +
this.getField("P6eval_competences.manageriales.18").value +
this.getField("P6eval_competences.manageriales.19").value +
this.getField("P6eval_competences.manageriales.20").value +
this.getField("P6eval_competences.manageriales.21").value +
this.getField("P6eval_competences.manageriales.22").value +
this.getField("P6eval_competences.manageriales.23").value +
this.getField("P6eval_competences.manageriales.24").value +
this.getField("P6eval_competences.manageriales.25").value +
this.getField("P6eval_competences.manageriales.26").value +
this.getField("P6eval_competences.manageriales.27").value +
this.getField("P6eval_competences.manageriales.28").value +
this.getField("P6eval_competences.manageriales.29").value +
this.getField("P6eval_competences.manageriales.30").value +
this.getField("P6eval_competences.manageriales.31").value;
if (getField("TOTAL").value == "21") {
var expTplt = getTemplate("NIVEAU MATURE");
expTplt.spawn(numPages, true, false);
}
I think you should use parseInt() method cause the values which are returned are not Integer rather they are Strings.