Web Applications as Desktop Flavor with Ajax Agent

With ajax agent, transfer data between the browser and the web server (HTTP request) occurs asynchronously. This is what allows a web page to request a small amount of data from the server without reloading the entire Web page.

how to use ajax agent with javascript and php

Ajax usability in a web, is an important thing. Why so, because in ajax there are many advantages, for example, you may often see a website which if clicked on a particular button or link, the web page is not switched to the new page, but rather only partial pages are changed, it was called ajax, ajax function which is called partial page of a website so that the website can be accessed quickly.

With ajax agent techniques we can develop web applications fast and responsive as well as desktop applications. The web applications have characteristics such as desktop applications are often referred to as Rich Internet Application (RIA).

 Using ajax agent class to connect javascript with php function 

Ajax Agent Class is a very easy to use, yet very powerful open source framework for rapidly building AJAX or Rich Internet Applications (RIA). It is based on JSON & hence supports complex data types like associated arrays & objects.Aims to make Ajax work as simple as possible. Based on KISS (keep it simple stupid)

There are three steps to get started with the ajax agent :

<?php
include_once('agent.php'); /*reload ajax agent class*/
$agent->init(); /* initialize the agent framework & instantiate the server side */
?>
<script>
function javascript(){
agent.call('php_file','php_function', 'client_callback', param1, param2, ... etc); /* call php function from javascript browser */ }
function client_callback(value){
 alert(value);
}
</script>

 Example use ajax agent in case : 

1. Create php file as index.php and copy code below to your file :

<?php
include_once('agent.php');
$agent->init();
?>
<html>
<script >
function myname()
{
  var name=document.getElementById('name').value;
  agent.call('functions.php','myname_function', 'client_callback', name);
  return false;
}
function client_callback(value)
{
  document.getElementById('result').innerHTML=value;
  return false;
}
</script>
<body>
<label>Text your name here : </label><input type="text" id="name" />
<button onclick="myname();">Click Me</button>
<span id="result"></span>
</body>
</html>

2. Copy Agent.php on the same folder with index.php, you can download ajax agent < a href=”http://seegatesite.com/wp-content/uploads/2014/10/ajaxagent-0.4.tar.gz” title=”ajax agent download” alt=”ajax agent download”> here
3. Create functions.php file on the same folder with index.php and copy this script below

<?php
  function myname_function($name){
    $retval= 'Hello, my name is '.$name;
    return $retval;
}
?>

I hope it can help you to create web application as desktop flavor with ajax agent. I implement ajax agent on my tools to amazon asin grabber, amazon scraper product,etc.. please visit http://seegatesite.com/tools/ to demo site

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: