- Dr. Steven Bitner
Ajax & cron jobs Dr. Steven Bitner AJAX (Asynchronous - - PowerPoint PPT Presentation
Ajax & cron jobs Dr. Steven Bitner AJAX (Asynchronous - - PowerPoint PPT Presentation
Ajax & cron jobs Dr. Steven Bitner AJAX (Asynchronous JavaScript and XML) So far in this course All of our interactions have been server side or client side AJAX blurs the lines a bit AJAX Change out part of a page Policy
AJAX
(Asynchronous JavaScript and XML)
So far in this course…
All of our interactions have been server side or client side AJAX blurs the lines a bit
AJAX
Change out part of a page
Policy
Can only perform local AJAX calls
You can however override subdomain blocking
e.g. by defualt www.mysite.com cannot make AJAX calls to
info.mysite.com but that setting can be changed.
First steps
First, you need JavaScript to create an object
jQuery can do this for you
Great because it handles cross browser issues related to the different
- bject types in IE vs Chrome etc.
This object is an HTTP request object that goes to a specified
url
in jQuery, via the ajax, load, get or post method – we'll talk
about load since it is sufficient for all that we have learned
Load
For loading a web page directly into a page element
Requires result to be text or html
$("button").click(function(){
$("#myDiv").load("mydiv.php"); });
Partial load
You can also load only a portion of the returned data
$("#myDiv").load("mydiv.php #someDiv");
Sending a GET type request
For loading a static page where no arguments are needed
$("button").click(function(){
$("#myDiv").load("mydiv.php?" + "username=bitners" + "&show=Always Sunny in Philidelphia"); });
Sending a POST type request
For loading a static page where no arguments are needed
$("button").click(function(){
$("#myDiv").load("mydiv.php", { username:"bitners", show:"Always Sunny in Philidelphia" }); });
Cron
Cron jobs
Some tasks just need to be completed regularly
Daily status report for your website
How many new users How many downloads of particular files etc.
Weekly email blast to followers
Cron is the way
Linux/Unix has a built in utility for this Controlled by a text file called crontab
Crontab fields
1.
Minute of execution
2.
Hour of execution (24 hour)
3.
Day of execution
4.
Month of execution
5.
Day of the week (0 => Sunday, 6 => Saturday)
6.
File to run
Crontab example line
30 0 * * * emailBlast
This would run the job at midnight thirty every day of every
month
59 23 * * 0,6 weekend
This would run weekend every Saturday and Sunday at one
minute before midnight
cd /home/faculty/bitners/public_html && mailer To run a PHP script, must first call executable, e.g.
/usr/bin/php mailer.php
Editing the crontab file
Just type `crontab –e` at the command prompt in puTTY This will open the file for editing