phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP - AJAX: Implementing PHP DOM and GET Parameters

Tag: AJAX, javacript, DOM, CSS, client side, javascript event, Parameter, GET, XML   Category: PHP Application
post: 18 Mar 2008 read: 277


PHP AJAX Step By Step Tutorial - part 6: At previous post, we use plan text to generate calculation result. Now, we modify in order to generate xml format.

Create a file named "calc.php" within www/test/ajax. Enter following code:


<?php

switch($_GET['func']){
  case "add":
    $result = ($_GET['param1'] + $_GET['param2']);
	break;
	
  case "min":
    $result = ($_GET['param1'] - $_GET['param2']);
	break;  
	
  case "div":
    $result = ($_GET['param1'] / $_GET['param2']);
	break;  	
	
  case "mul":
    $result = ($_GET['param1'] * $_GET['param2']);
	break;  	

}

header('Content-type: text/xml');

$dom = new DOMDocument();

$datas = $dom->createElement('datas');
$dom->appendChild($datas);

$calculation = $dom->createElement('calculation');
$calculationText = $dom->createTextNode($result);
$calculation->appendChild($calculationText);

$datas->appendChild($calculation);

$xmlString = $dom->saveXML();
echo $xmlString;

?>

Try to point your browser like http://localhost/test/ajax/calc.php?param1=10¶m2=5&func=add. You will get like this:

xml format



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting