Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

PHP class notes-unit 5, Lecture notes of Programming Languages

PHP class notes-unit 5 syllabus: AJAX - Advanced AJAX.

Typology: Lecture notes

2018/2019

Uploaded on 08/12/2019

krishnavalli-singaravelan
krishnavalli-singaravelan 🇮🇳

5 documents

1 / 42

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Contents
AJAX..................................................................................................................................................... 1
AJAX with PHP..................................................................................................................................................... 3
Passing data to server with GET............................................................................................................................... 3
Passing data to the Server with Post..........................................................................................................................3
Handling XML..................................................................................................................................................... 5
Handling XML with PHP..........................................................................................................................................8
ADVANCED AJAX..................................................................................................................................................... 10
Handling Concurrent AJAX Request...................................................................................................................... 10
Downloading image in AJAX..................................................................................................................................... 12
Downloading JavaScript with AJAX...........................................................................................................................12
Connecting to Google Suggest [Real Time Application with AJAX].....................................................................13
Connecting to other domain using AJAX................................................................................................................15
Logging in with AJAX & PHP....................................................................................................................................15
Getting Data with Head Requests and AJAX..........................................................................................................16
DRAWING IMAGES ON THE SERVER...................................................................................................................... 17
Creating an Image..................................................................................................................................................... 18
Destroying Image Files................................................................................................................................................18
Displaying Images in HTML Pages........................................................................................................................ 19
Drawing Lines..................................................................................................................................................... 19
Setting Line Thickness............................................................................................................................................ 20
Drawing Rectangles.....................................................................................................................................................20
Drawing ellipses..................................................................................................................................................... 20
Drawing ARCS..................................................................................................................................................... 21
Drawing Polygons..................................................................................................................................................... 21
Filling in figures..................................................................................................................................................... 22
Drawing Individual Pixels...........................................................................................................................................22
Drawing Text..................................................................................................................................................... 22
Drawing Vertical Text..................................................................................................................................................23
Working with Image Files...........................................................................................................................................23
Tilling Images..................................................................................................................................................... 25
Copying Images..................................................................................................................................................... 25
UNIT 5
UNIT 5 | Page 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a

Partial preview of the text

Download PHP class notes-unit 5 and more Lecture notes Programming Languages in PDF only on Docsity!

Contents

  • AJAX.....................................................................................................................................................
    • AJAX with PHP.....................................................................................................................................................
      • Passing data to server with GET...............................................................................................................................
      • Passing data to the Server with Post..........................................................................................................................
    • Handling XML.....................................................................................................................................................
      • Handling XML with PHP..........................................................................................................................................
  • ADVANCED AJAX..................................................................................................................................................... - Handling Concurrent AJAX Request......................................................................................................................
    • Downloading image in AJAX.....................................................................................................................................
    • Downloading JavaScript with AJAX...........................................................................................................................
      • Connecting to Google Suggest [Real Time Application with AJAX].....................................................................
      • Connecting to other domain using AJAX................................................................................................................
    • Logging in with AJAX & PHP....................................................................................................................................
      • Getting Data with Head Requests and AJAX..........................................................................................................
  • DRAWING IMAGES ON THE SERVER......................................................................................................................
    • Creating an Image.....................................................................................................................................................
    • Destroying Image Files................................................................................................................................................
      • Displaying Images in HTML Pages........................................................................................................................
    • Drawing Lines.....................................................................................................................................................
      • Setting Line Thickness............................................................................................................................................
    • Drawing Rectangles.....................................................................................................................................................
    • Drawing ellipses.....................................................................................................................................................
    • Drawing ARCS.....................................................................................................................................................
    • Drawing Polygons.....................................................................................................................................................
    • Filling in figures.....................................................................................................................................................
    • Drawing Individual Pixels...........................................................................................................................................
    • Drawing Text.....................................................................................................................................................
    • Drawing Vertical Text..................................................................................................................................................
    • Working with Image Files...........................................................................................................................................
    • Tilling Images.....................................................................................................................................................
    • Copying Images.....................................................................................................................................................
  • UNIT

AJAX

  • AJAX stands for Asynchronous JAvascript Xml.
  • AJAX is the basics for Web 2.0.
  • Implementing AJAX will give a web application the look and feel of desktop application.
  • AJAX applications do not refresh the entire browser display every time the user does something.
  • AJAX can communicate with server download data and display the data in some part of the web page without having to reload the web page.
  • AJAX is implemented using Java Script and XML.
  • PHP is used with AJAX to communicate with the server.

Writing AJAX program: Program 5- Index.html An Ajax demo

Sending Ajax data with POST

_ _

The fetched message will appear here.

In the above program,

  • As the data’s are not sent through ?URL encoded moe, the coding for two buttons are written as follow: _
    <input type = “button” value = “Fetch message 1” onclick = “getData (‘choosem.php’, ‘targetDiv’, 1)”> <input type = “button” value = “Fetch message 2” onclick = “getData (‘choosem.php’,‘targetDiv’, 2)”>
_ - The data’s are sent to the getData function as its 3rd^ argument, - The getData function definition is changed to take 3 arguments - Set the method to open object to post. - Additional code is included to indicate to the server-side code that the data’s are encoded as POST encoding format through this line: _XMLHttpRequestObject.setRequestHeader (‘Content-Type’, ‘application/x- www- form-urlencoded’);_ - Finally the encoded data is sent to the server through the send method as follow: _Function getData (dataSource, divID, data) { If (XMLHttpRequestObject) {_

Soda Cheese Salami Store.html Using Ajax with XML

Using Ajax with XML



your selection will appear here.
In the above program,
  • The open function of XMLHttpRequestObject will have “products.php? Items = 1” as its target parameter.
  • A value of 1 for items will return the products1 entries and 2 will return the second list of products.

ADVANCED AJAX

  • AJAX accepts multiple XMLHttpRequest from client to server.
  • AJAX allows downloading from multiple servers.
  • JavaScript files can be downloaded through AJAX and can be executed from the browser.

if (XMLHttpRequestObjects[index].readyState == 4 && XMLHttpRequestObjects[index].status == 200) { var xmlDocument = XMLHttpRequestObjects[index].responseXML; products = xmlDocument.getElementsByTagName("item"); listproducts(); } } XMLHttpRequestObjects[index].send(null); } }

In the above code,

  • Each button uses separate object from the array. Solution 3: using JavaScript inner function.
  • An inner function is a function that’s contained inside another function. format: function Outer(data) { var var1 = data; function inner (var2) { alert (var1 + var2); } }
  • Every time there is a call to outer function, a new copy of that function is created, means a new value is stored as var1.
  • The inner function will have access to that value.
  • Similarly in each call, a new XML Http Request Objects is created and that object is available to any inner function.
  • Therefore, the code to create and fill the variable XML Http Request Objects is placed inside the function getproducts1 and getproducts2. Then when there is a call to the function, a new XML Http Request Object is created and the anonymous inner function will use the new object automatically.

Downloading image in AJAX.....................................................................................................................................

  • When downloading images, the name of the image is downloaded. To actually download the image, AJAX depends on Dynamic HTML in the browser.

Downloading JavaScript with AJAX...........................................................................................................................

  • When there is a request to external website, the return data can be in JavaScript.
  • Any kind of JavaScript can be sent back from the server to the AJAX-enabled JavaScript.
  • E.g.: Downloading JavaScript with Ajax