INTRODUCING CJAX - - FOR PHP - A FREE AJAX LIBRARY

  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 565
  • Loc: Fort Worth, TX

Post 3+ Months Ago

If you know php CJAX is a great way to take your applications to the next level.


I was originally doing this post on the other post as an answers, but i would like to post it itself to see if this could help anyone that is interested.


FINALY FREE AND INDEPENDENT FROM HTML FORMS!

CJAX Its an Ajax library. -
PHP-JAVASCRIPT - that can do more things

I know this tread is not very organized, but focus on the topic

FOR WHAT?
contacts forms
seach queries
user login
load information
interact from db in real time
avoid load the page alot
post any info without using forms
get users input
these are the ones i can think of at this time, sure you can do anything!


WORKS WITH
buttons
images
text links
submit buttons
checkboxs
radiobuttons
combo boxes
page load :)
and any other element or object

SUPPORTED EVENTS
onclick
onchange
onmouseover
onmouseout
and all ther other events that exist in javascript
your extended onces?


Who can use this?
Anybody that doesn't know any javascript, and if you know, still its not necessary but its ok. and with little knowledge of php




background:

CJAX came up, because I was having a lack or resources of how to-do things with Ajax, and started messing with the code, until it worked. to make a functions actually work, and that could not be done with regular php code, or it needed more than just common functions average users use. for example the header('location: ') was redirecting me to another page inside a div element, and (will mention this in the next explanation) the javascript doesn't work when calling the xmlhttpobject, so nothing could be done the way i want it, that is why i made some tweaks to get the output of the xmlhttprequest and make some keyword that would later would be read by several the javascript methods, and transformed to executable code, with pre-made functions

installation:
as easy as to copy a folder to your domain root
and include a file with php like for example something like this
PHP Code: [ Select ]
 
<?php include $_SERVER['DOCUMENT_ROOT']."/cjax/core/classes/cjax_config.php";?>
  1.  
  2. <?php include $_SERVER['DOCUMENT_ROOT']."/cjax/core/classes/cjax_config.php";?>



notes:
you don't even have to know javascript to use CJAX!
and the php code to use is as simple as it can possibly be


an example can be, this is a real page that really exists on the site, however this has been modified as a demo only,
Hit on the search button. some users will come up, then click on delete, or view, view is where i set a user whether the service is available to him or not, and it uses the 'onchange' event to interact with the database.
the delete uses the alert boxes, try it

http://importerx.com/admin/users_services2.php is not designed to be a demo, a just made some modification to disable to actually delete users from the db, but it actually does in real life, like this anything , any kind of project can be done with CJAX
if you notes it removes the row of the user when you click on delete
it uses this method

PHP Code: [ Select ]
$CJAX->remove("row");  

and i will remove it! not much drama. i will remove anything that has the id you specify. since i am using a loop there, its assing the rows the user ID



You can assign text!,
for example instead of "loading"
it can say login in.. or sign in .. or delete, working, changing.., anything!

just using this,

PHP Code: [ Select ]
$CJAX->text = 'intetacting with the server..';


so, the famous loading.. you can change it to anything you would like to!




well you can be thinking mmm why use $CJAX->location to redirect a page, if you can do that with javascript, or header('location: page') with php , or Response.Redirect "page" with asp, (they don't work with the xmlhttprequest object)
Well the difference is that this function is called withing another page, thing that i haven't seen any where else, because using javascript code can't be execute on the innerHTML of an object when the xmlHTTP request has been called.
other ways to use cjax, is like this, using alert messages,, instead of using javascript alert('message');
you can use it like this
PHP Code: [ Select ]
<?php
 
$CJAX->alert('message');
 
?>
  1. <?php
  2.  
  3. $CJAX->alert('message');
  4.  
  5. ?>


yes you are popin up an alert message, within your php code. it can be directly from the database. the page never reloads using cjax! unless you want it to.
you can also, assign a loading image,
$CJAX->image ="loading.gif";

this is the animated gif you see when AJAX IS loading a remore/relative page
another way of using this library is
PHP Code: [ Select ]
$CJAX->load('mydiv',page2.php');


what this will do it will load another page, into your current page, when it loads!, i am sure you have seen it before on site like MSNBC http://video.msn.com/v/us/msnbc.htm yes with CJAX you can do all that!. forget the iframes!


my site uses cjax all the way!,, in the login, in the news section, in the when updating users info from the database, when editing users info.

i am going to go ahead an put a small example here, with cjax you can do anything you can think of!..


lets say a user is logged into yours website, and wants to change the password

PHP Code: [ Select ]
$CJAX->image='loading.gif';
 
$CJAX->JSevent="onclick";
  1. $CJAX->image='loading.gif';
  2.  
  3. $CJAX->JSevent="onclick";



PHP Code: [ Select ]
$changepw = $CJAX->call("changediv","?cmd=changepw");

//SOME EXPLANATION
// call is the function tha is been executed to make the request
// changediv, is our element that we are using as a place holder, where the output will be sent to
// ?cmd=changepw is a query that will send the var cmd to the $_get method. changepw is the query string

?>
<!--lets go ahead an place our div here -->
<div id='changediv'></div>


now lets make a submit button, that will send the request,

PHP Code: [ Select ]
<input type='submit' value='change password' <?php echo $changepw;?>>


this is all what you need to execute the command, you can assign an event, we assigned
"onclick" we can also assign "onchange" to a combo box, so every time you choose a different option, i will interact directly with the database.


ok lets continue, now you put the action on of the $_GET REQUEST


PHP Code: [ Select ]
$commitemail_text = $CJAX->value("txtchangpassword");
 
$commitpassword = $CJAX->call("changediv","?cmd=do_changepw&pw='$commitpassword_text'");
  1. $commitemail_text = $CJAX->value("txtchangpassword");
  2.  
  3. $commitpassword = $CJAX->call("changediv","?cmd=do_changepw&pw='$commitpassword_text'");


also you can use the option value to get the value of any element, and they are passes to the php variables
above we are using the value option to get the 'txtchangepw' or the new password that will be saved to the database


PHP Code: [ Select ]
if ($_GET['cmd'] == "changepw") {
 
Echo "<h3>Change your password</h3>";
 
 
 
Echo "<label for='txtchangepw'>New Password:&nbsp;</label>";
 
echo "<input type=password id='txtchangepw'>";
 
echo "<input type='submit' value='change' ".$commitpassword."><input type=button value='cancel'".$reset.">";
 
echo "<br />You will be re-directed to the login page after you change your password";
 
exit;
 
}
 
 
  1. if ($_GET['cmd'] == "changepw") {
  2.  
  3. Echo "<h3>Change your password</h3>";
  4.  
  5.  
  6.  
  7. Echo "<label for='txtchangepw'>New Password:&nbsp;</label>";
  8.  
  9. echo "<input type=password id='txtchangepw'>";
  10.  
  11. echo "<input type='submit' value='change' ".$commitpassword."><input type=button value='cancel'".$reset.">";
  12.  
  13. echo "<br />You will be re-directed to the login page after you change your password";
  14.  
  15. exit;
  16.  
  17. }
  18.  
  19.  


This will show up, a text field where the users types their new password, this should go on top of the page, also with the process to actually update the password




this will actually change the password, note that overall we haven't move to different page at all, everything happening on the same page without refreshing the page. or posting forms.


PHP Code: [ Select ]
 
if ($_GET['cmd']=='do_changepw'){
 
 
 
 
 
if (change_password($_SESSION['userid'],$_GET['pw'])) {
 
$CJAX->alert("Your password has been changed. \nNow you are been re-directed to login page... click OK to continue \n use your new password to login");
 
 
 
$CJAX->location("login");
 
}
 
else
 
{
 
echo ("\n<br />ERROR: Your password can not be changed, make sure your new password is valid");
 
}
 
 
 
exit; }
  1.  
  2. if ($_GET['cmd']=='do_changepw'){
  3.  
  4.  
  5.  
  6.  
  7.  
  8. if (change_password($_SESSION['userid'],$_GET['pw'])) {
  9.  
  10. $CJAX->alert("Your password has been changed. \nNow you are been re-directed to login page... click OK to continue \n use your new password to login");
  11.  
  12.  
  13.  
  14. $CJAX->location("login");
  15.  
  16. }
  17.  
  18. else
  19.  
  20. {
  21.  
  22. echo ("\n<br />ERROR: Your password can not be changed, make sure your new password is valid");
  23.  
  24. }
  25.  
  26.  
  27.  
  28. exit; }


as simple as that, you can do anything with CJAX! and its constantly updated and new functions are been added all the way!, its not just AJAX,httprequest, its a library that actually perform pre-made actions when you call them






if anybody likes what you heard let me know i make sure you get a copy, its free. well if any of that helps, i hope it does lol.


if you want to see a real life example see my site http://importerx.com/ not trying to promote my site or anything, just to see what you can also do. when you go to change password http://importerx.com/password and enter any random email (make sure is in good format like aaa@bbb.com or it will jump to other kind of error), it will give you an alert box error, interacting directly from the database and all the code that was used was

PHP:
PHP Code: [ Select ]
$CJAX->alert("message");


ofcourse after checking the database if the email is actually a valid one from a user


also the benefits are that everything is server side.

I could have the menu load with CJAX too the only problem is that the xmlhttprequest is limited that doesn't allow to execure arbitrary javascript code on the requested pages, so all the actions that are in CJAX are been code the hard way, its not just javascript and of course you can do more things like assigning style to the loading element on the loading state


also comments are welcome, also if anyone would like to help out with documentation that would be great


What can you do with CJAX?

submit all kind of web forms without reloading the page
Interact with data from the database
Practically anything you already do on your site! but it turns it into Ajax!

-Can do totally different things on each scenario
-Only 2 lines of code to run CJAX on your site!






Loading image

loading image is one of the coolest futures of cjax!, it allows you to set your own image on
the loading screen to personalize your site even more!, and this great future allows you
to set an image on every scenario, but if you prefer not to miss with this, a default loading
image will be used.



a default loading image is been used, but you can also customize by adding this line of code

giving an absolute path to the image

PHP Code: [ Select ]
$CJAX->image="http:///yoursite.com/images/loading.gif";




Or


giving a relative path to the image


PHP Code: [ Select ]
$CJAX->image="images/loading.gif";

<?php


PHP Code: [ Select ]
include ("../cjax/core/cjax_config.php");
 
 
 
$CJAX->image="http:///yoursite.com/images/loading.gif";
 
 
 
 
 
 
 
$request = $CJAX->cjax_call ("div_test");
  1. include ("../cjax/core/cjax_config.php");
  2.  
  3.  
  4.  
  5. $CJAX->image="http:///yoursite.com/images/loading.gif";
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. $request = $CJAX->cjax_call ("div_test");

//Now lets test it!
//Testing the code its the easier part!


PHP Code: [ Select ]
echo "<div id='div_test'></div>";
 
echo "<a href='javascript&#058;(void);' $request>Test loading screen</a>";
 
 
  1. echo "<div id='div_test'></div>";
  2.  
  3. echo "<a href='javascript&#058;(void);' $request>Test loading screen</a>";
  4.  
  5.  



you can download cjax here
http://importerx.com/download

i haven't got to any documentation, i really suck at it.


if you decide to use it, post here here you current form /and i will show you how to set it up
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 565
  • Loc: Fort Worth, TX

Post 3+ Months Ago

I know this thread is old, but I am proud to say ozzu was the first time Cjax was introduced publicly, today, with more than 20,000 downloads, and widely known, Cjax has evolved very powerful Ajax Framework, it is widely known in the CodeIgniter community as well since I built a library where Cjax is integrated and is the go-to, Ajax Solution for CodeIgniter.

Checkout the Demos:
http://cjax.sourceforge.net/examples/

Of course, much of the description above does not longer apply, since Cjax has morphe alot in the past few years, and has been rewritten to meet the latest technology at least 3 times. Started as a library, now is a full fledged Ajax Framework, bug free.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.