Clarification for Ajax usage

MrGuvernment

Fully [H]
2FA
Joined
Aug 3, 2004
Messages
24,359
I have been reading alot about Ajax and i for the most part understand what it is and what it does.

What i am not sure of is this.

Currently our company has a PHP /MySQl system for customer service to pull data on players and various other info we may need from raw data we get from our servers.

The system is dated and slow, long page loads, loading similar data, this is why i think Ajax could be an option to try.

Now, since the back end is essentially built, is it possible to use what i already have in PHP and easily convert it into using ajax based system?

Would i have to use Java or XML to really get the feature set of Ajax based sytem?

What are the requirements to use Ajax? (Java / XML / xhtml?)
 
i have come across Sajax and Tigermouse....they "sound" like something i could try to use..
 
First of all AJAX is Asynchronous JavaScript and XML. Java != JavaScript.

AJAX makes use of XMLHTTPRequest objects to fetch information from the server without reloading the pages, usually the information is returned in the from of XML which can be generated by any server backend such as PHP, JSP, Servlets, ASP or some kind of Web Service just to name a few things. Basicly you use javascript to create an XMLHTTPRequest Object you fire it off either synchronously or asynchronously to a URL, then the JavaScript parses the response for w/e information you requested and updates the page accordingly.


You can find a good primer on AJAX at the following link.

http://www.w3schools.com/ajax/default.asp
 
While AJAX can create seemingly faster loading pages (by loading only specific sections), be careful about going overboard with it. Too much AJAX can end up making your site even slower.

I would advise that before you plunge into AJAX that you first examine the code of your current site to see if there are any glaring efficiencies. If your site is slow because of inefficient queries, then running those same queries through an AJAX request is not going to make anything better. If it's slow because of network issues, AJAX won't fix that either.

The purpose of AJAX is to make the user-experience more fluid and responsive to their needs, NOT to make your site faster.
 
i understand that, i plan to use which method i go with sparingly to get the job done and that is it.

the base code i am working with is very straight forward, simple select queries to show information of customers, the slow side of it is when say the a customer's profile is up and showing, and then we want to see if any other accounts are associated with that customer, it pulls all the info over again, i was thinking Ajax to give that more fluid feel between displaying data for our employee's in new frames and such.

But since this is all something i will be learning from scratch i am open to other coding options.. ruby / asp...
 
First of all AJAX is Asynchronous JavaScript and XML. Java != JavaScript.

AJAX makes use of XMLHTTPRequest objects to fetch information from the server without reloading the pages, usually the information is returned in the from of XML which can be generated by any server backend such as PHP, JSP, Servlets, ASP or some kind of Web Service just to name a few things. Basicly you use javascript to create an XMLHTTPRequest Object you fire it off either synchronously or asynchronously to a URL, then the JavaScript parses the response for w/e information you requested and updates the page accordingly.


You can find a good primer on AJAX at the following link.

http://www.w3schools.com/ajax/default.asp


missed this one, going to take a read, grabbed some items on javascript as well to start reasding up on
 
So been reading plenty, mainly trying to get a grasp of javascript right now.

from reading, i can use PHP and MySQL as part of the ajax system.

i am trying to get our old site also moved off an older system (apache and php 4) to a newer IIS7 and php 5, but of course the php pages dont work with errors like mad moving it over to IIS 7 (yes they should work just fine, but that says more about the past coding, it isnt cross compatible between http servers!), even after editing and trying to fix (enabling things like global variables cause the last guy did all his work with those on!)

So i am now thinking i will start to redo the code as i go along to get it moved to this new system.

Is there a site, or can someone summarize for me some best practices for using PHP and MYSQL with Ajax, more so in terms of security, what i could do, shouldn't do? I have orderd some books already as well for more studying.

Right now employee's log into a front end, no ssl and a simple php login scripts that connects to MySQL to check if the info is right, i don't believe there is any encryption at all either...

i was considering adding SSL to the system, but also wanted to make sure the login script was as secure as possible

this is what is used right now

Code:
<?php 
	//Authorization for access for the script, the system uses the globals for windows and accesses the ************************ Database
	
	$messcount=0;
	// authorization script
	$auth = 0; 
	if (!($dblink=mysql_connect("***************", "***********", "******************")))
	{
		header("Location:/cantconnect.php");
		exit;
	}
	mysql_select_db("technotes",$dblink);
	$dbpassword=mysql_query("select password,access,username from ************** where username='$PHP_AUTH_USER' ",$dblink);
	$password=mysql_fetch_row($dbpassword);
	if ($PHP_AUTH_PW == "$password[0]" ) 
	{
		$auth = $password[1];
		//adds a line to the ************ logs
		mysql_query("insert into ************************** (tstamp, loginid, password, success, page, IPaddr) values (Now(),'$PHP_AUTH_USER','$PHP_AUTH_PW', 1, 'main:$REQUEST_URI','$REMOTE_ADDR')",$dblink);
		//print("insert into *************** (tstamp, loginid, password, success, page, IPaddr) values (Now(),'$PHP_AUTH_USER','$PHP_AUTH_PW', 1, 'main:$REQUEST_URI','$REMOTE_ADDR')");
		$dbmesscount=mysql_query("select count(message.recid) from *************** inner join passwords on (*****************.touser=passwords.usernum) where *****************.username='$PHP_AUTH_USER'",$dblink);
		//$messcount=mysql_fetch_row($dbmesscount);
	}
	else
	 {mysql_query("insert into ******************* (tstamp, loginid, password, success, page, IPaddr) values (Now(),'$PHP_AUTH_USER','$PHP_AUTH_PW', 1, 'main:$REQUEST_URI','$REMOTE_ADDR')",$dblink);}
	if ( $auth == 0 or $PHP_AUTH_PW==" ") 
	{ 
    	//Access failure
		header( "WWW-Authenticate: Basic realm=\"Authorization Required!\"" ); 
    	header( "HTTP/1.0 401 Unauthorized" ); 
    	echo 'Authorization Required!'; 
    	exit; 
    } 
	$use=$PHP_AUTH_USER;
 
php/mysql work just fine. I really like the abstraction between the interface (javascript/html) and the data serving layer (php).

I usually have 2 main scripts besides the one(s) which serve pages. 1 which serves out html to be displayed in dialogs and in portions of the pages and one which serves out pure data in XML or JSON format.

Any authentication mechanism you use for serving regular pages will apply for your asynchronous requests. Just as you would authenticate to serve a webpage authenticate to serve your AJAX requests.

I do recommend you look into a javascript library. Personally I'm a big fan of YUI as it takes care of implementation incompatibilities and the like. Its also a well thought out and implemented toolkit/widget library.
 
I do recommend you look into a javascript library. Personally I'm a big fan of YUI as it takes care of implementation incompatibilities and the like. Its also a well thought out and implemented toolkit/widget library.

I second that.. A JS framework will make your life much, much easier as it eliminates most of the cross-browser sillyness and makes it much easier to get complex UI behavior up a running in no time. They are also fairly easy to learn. I like jQuery myself, but any of the well known frameworks like Prototype, YUI, Dojo, script.aculo.us, etc.. should be just fine.
 
Back
Top