Originally Posted by
phantom007
Sir kolz can I ask your number, I need your help regarding of programs, mine 09175364810. tnx
I'm currently based in Singapore, pero ang concept about calling your php script is quite simple. I've attached sample code below where you can use sa imong project. You only require jQuery for ajax as the lone dependency:
index.html
HTML Code:
<html>
<head>
</head>
<body>
<p>Current time is : <div id="timer"></div></p>
<p>Number of time updatetime() called: <div id="callcount"></div></p>
<p>
<hr/>
Database script is called every 20 seconds ...
Enter your name (becomes input to getdata.php):
<input name="name" type="name" maxlength="50" id="getdataTxt" class="getdataInput"/>
<!-- This is the section where php script results will be displayed -->
<div id="databasereply">
<!-- Here we display the database table from php -->
</div>
<hr/>
</p>
</body>
<!-- Include scripts here ... -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- Include JQuery (for ajax) -->
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js"></script> -->
<script type="text/javascript" src="jquery-3.1.1.min.js"></script>
<script type="text/javascript">
function setnewdaytimer()
{
var now= new Date();
// Set the alarm to next day (tomorrow)
var tomorrow= new Date(now.getFullYear(), now.getMonth(), now.getDate()+1);
// Assign the callback function newdayalarm() if timer fires.
setTimeout(newdayalarm, tomorrow-now);
// We also want to update new time on the page every second
setInterval(ontimerupdate,1000); // 1000 = 1 second
// Call a php script every 20 seconds.
// To call the script once a day, then 2nd parameter would be
// 1000 * 60 * 60 * 24 -> which is 1000 (sec) * 60 (mins) * 60 (hr) * 24
setInterval(ondatabaseupdate, 1000 * 20); // 1 hr = 1000 * 60 (seconds) * 60 (minutes)
}
function newdayalarm(){
// Displays an alert box
alert((new Date()).toLocaleTimeString());
// TODO: Call php script via ajax
}
function ontimerupdate()
{
var today = new Date();
if (typeof ontimerupdate.count == 'undefined')
{
ontimerupdate.count = 0;
}
document.getElementById("timer").innerHTML = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
document.getElementById("callcount").innerHTML = ontimerupdate.count + " times!";
// increment counter
ontimerupdate.count ++;
}
function ondatabaseupdate()
{
var inputname = document.getElementById('getdataTxt').value;
if (!inputname || (0 === inputname.length))
{
inputname = "Istorya.net";
}
// Call your PHP script here (getdata.php) via ajax (JQuery)
// The result of getdata.php is stored as a JSON format
// where you can retrieve the text and display it on the
// html page
var request = $.ajax({
type: "POST",
url: "getdata.php",
data: { name: inputname },
dataType: 'JSON',
success: function(datareply)
{
// Display the result of PHP script on the page
document.getElementById("databasereply").innerHTML = datareply.text;
console.log(datareply.text);
}
});
}
// Whe the web page loads, call the setnewdaytimer() function to
// set the timeout.
window.onload=setnewdaytimer;
</script>
</html>
getdata.php
PHP Code:
<?php
// A very simple PHP script, uses the variable 'name' from
// a POST request.
// TODO: Do a database query through mysql, then store the result in
// and array before encoding with json_encode()
if(isset($_POST['name']) && !empty($_POST['name'])) {
if ($_POST['name'] === "Rodrigo Duterte")
{
echo json_encode(array("text" => "Welcome President ".$_POST['name']));
}else
{
echo json_encode(array("text" => "Welcome ". $_POST['name'] . ", you low life son of a *!@#$!" ));
}
}
?>
Ayaw kalimot ug download sa jQuery (".js") https://jquery.com/download/ script and put it on the same directory where the two files above reside.