Ajax & cron jobs Dr. Steven Bitner AJAX (Asynchronous - - PowerPoint PPT Presentation

ajax cron jobs
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1
  • Dr. Steven Bitner

Ajax & cron jobs

slide-2
SLIDE 2

AJAX

(Asynchronous JavaScript and XML)

slide-3
SLIDE 3

So far in this course…

 All of our interactions have been server side or client side  AJAX blurs the lines a bit

slide-4
SLIDE 4

AJAX

slide-5
SLIDE 5

Change out part of a page

slide-6
SLIDE 6

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.

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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"); });

slide-9
SLIDE 9

Partial load

 You can also load only a portion of the returned data

$("#myDiv").load("mydiv.php #someDiv");

slide-10
SLIDE 10

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"); });

slide-11
SLIDE 11

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" }); });

slide-12
SLIDE 12

Cron

slide-13
SLIDE 13

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

slide-14
SLIDE 14

Cron is the way

 Linux/Unix has a built in utility for this  Controlled by a text file called crontab

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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

slide-17
SLIDE 17

Editing the crontab file

 Just type `crontab –e` at the command prompt in puTTY  This will open the file for editing