Follow vBSEO on Twitter
vBulletin Modifications
  • Forums
  • Add-Ons
  • Template Modifications
  • Styles
  • Graphics
  • Tutorials
  • Support Center
  • Register
  • vBulletin SEO

Member Log In

Site Navigation

  • Register
  • Members List
  • Social Groups
  • Search
  • Today's Posts
  • Mark Forums Read

Latest Modifications

  • [vB 3.6.x] StopSpam
    By: flappi282
  • [vB 3.8.x] vBulletin Chat Addon for...
    By: 123flashchat
  • [vB 3.5.x] 404 Page Redirect To...
    By: Ak Worm
  • [vB 3.8.x] 404 Page Redirect To...
    By: Ak Worm
  • [vB 4.0.x] 404 Page Redirect To...
    By: Ak Worm

Latest Template Mods

  • [vB 3.8.4] Images PassWordBox...
    By: cRs!MP
  • [vB 3.8.4] Footer Follow Ups
    By: Ak Worm
  • [vB 3.7.2] Worldofwarcraft blue...
    By: Mikeyodesigns
  • [vB 3.7.0] My Links
    By: blind-eddie
  • [vB 3.7.0] Pop-Up Warning Before...
    By: Thelonius Beck

Latest Styles

  • [vB 3.8.4] CompletevB - Skylight
    By: DreadKnight
  • [vB 3.8.3] [vB 3.8.4] Barcelona...
    By: hoiquantinhoc.com
  • [vB 3.8.3] Natures Walk by vBSkin...
    By: Chri5
  • [vB 3.8.3] Green Theme
    By: Robdog
  • [vB 3.8.2] Unreal T 3 - vB3.8.x
    By: Butcher

Latest Graphics

  • [vB ] [anim.]Team Ranks
    By: cRs!MP
  • [vB ] Abstract Circles (3...
    By: cRs!MP
  • [vB ] PlayStation Rank Images
    By: cRs!MP
  • [vB 3.6.12] Heavy Stroked Button...
    By: Shelley
  • [vB ] Minature Ranks.
    By: Shelley
vBulletin Modifications » General vBulletin Section » vBulletin Modification Tutorials » Integrating AJAX Technology Into Your Modifications
Reply

 

  • Thread Tools
Old 07-25-2006, 06:27 PM   #1
Zero Tolerance
Advanced Coder

Zero Tolerance's Avatar

Activity Longevity
0/20 13/20
Today Posts
0/3 sssssss31
Location: England
Age: 22
Zero Tolerance is on a distinguished road
Send a message via MSN to Zero Tolerance
Status: Offline Default Integrating AJAX Technology Into Your Modifications
This How-To will show you how to use the defined AJAX functions within vBulletin so developers can see how easily it is to integrate AJAX technology into modifications. Please note this tutorial is aimed at developers with some javascript knowledge.

Step 1 - Understand AJAX:

As many of you will know, AJAX gives the ability to pass data through a stream and receive any data returned with no reloading, so if you're thinking of integrating AJAX then you must first have a scenario where you wish to push data and receive it, data being received is not required however is probably the best part of AJAX in a users opinion due to the dynamic changes that occur to present the received data.

Step 2 - Setting Up AJAX:

Okay, so you want to set up AJAX, real easy, the first step is to create an AJAX Object, this can be done with ease using the vBulletin set-up, an example is below:
Code:
My_AJAX_Object = new vB_AJAX_Handler(true);
You'll notice the one and only passive variable here for the function 'vB_AJAX_Handler' is set to 'true', this determines whether to use asynchronous or not, set to false if you do not desire to use it, if you're unsure leave this set to true.

So now you have your AJAX Object set up, before firing data you'll need to to set the object to respond to a function for when it receives data, an example is below:
Code:
My_AJAX_Object.onreadystatechange(My_AJAX_Reciever);
Here the parameter is not so much a variable, but in fact a function name, in this case i put 'My_AJAX_Reciever', so that function must exist, an example function is below:
Code:
function My_AJAX_Reciever()
{
	if (My_AJAX_Object.handler.readyState == 4 && My_AJAX_Object.handler.status == 200 && My_AJAX_Object.handler.responseText)
	{
		alert('Data received successfully\n\n' + My_AJAX_Object.handler.responseText)
	}
}
This function pretty much checks the stream has loaded and sent data back to the browser, upon success it will alert you to say it was successful, and the data it received. How you handle the data is up to you.

Step 3 - Firing And Receiving Data:

So now you want to fire some data through AJAX, and get some back, let's first look how we fire data:
Code:
My_AJAX_Object.send('myfile.php', 'do=ajax&pagevar=text');
Let's take a quick overlook at the parameters used here:

Parameter 1 - The file you want to send the data to.
Parameter 2 - Post variables you want to send through.
In most cases your post variables (parameter 2) would fluxuate, and you may want to send some variables that users have inputted, if so you may want to take advantage of vBulletin's javascript emulation of urlencode(), first off you'd parse the variable in javascript before firing off, as shown below:
Code:
My_Variable = PHP.urlencode(My_Variable);
This makes the variable safe for the stream to send the data, however some characters will be broken, to fix these in your php when collecting the variable you would parse it like so:
PHP Code:
$My_Variable = convert_urlencoded_unicode($My_Variable); 
Okay, so you've now fired data off to 'myfile.php', with the variables: do (ajax) and pagevar (text). Now comes the PHP part, where you handle the data and output some back to be recieved:
PHP Code:
if ($_POST['do'] == 'ajax')
{
    echo 
$_POST['pagevar'];
    exit;
} 
Simple as that? Pretty much, ofcourse the desired data to be sent back due to the data sent is completely up to you, if you've set the javascript up with the examples used above you should get a message saying:
Quote:
Data recieved successfully

text
So if you're not sure, what the PHP outputs AJAX grabs, and just to ensure the script ends there it's best to make PHP stop execution of any code underneath by using exit;, this ofcourse it not required, just likely in most situations
Remember, to grab using AJAX what PHP outputted, the code is My_AJAX_Object.responseText

Final Line - Handling Data and Dynamics:

So you've managed to successfully fire some data off, and got some back, now you want to fiddle with it in Javascript and make changes to your page?
Then i'm afraid you're on your own for that job, how you handle the recieved data is completely upto you and the scenario you're using AJAX in.

If you wish to see more information on AJAX, i suggest you look at this tutorial i wrote a while ago for vBulletin.org, it includes more information on AJAX than posted here

http://www.vbulletin.org/forum/showthread.php?t=81626

Any questions/problems reply here and i'll try to resolve them for you, the code above is all written off the top of my head, but i don't see any errors myself, feel free to report them to me though

- Zero Tolerance
[:: Inferno Technologies ::]

RPG Inferno v3 Alpha 1 - Stretch your imagination
Reply With Quote
Old 07-25-2006, 08:21 PM   #2
Nick R
vBulletin Guru

Nick R's Avatar

Activity Longevity
0/20 13/20
Today Posts
0/3 sssss4450
Location: Cyberspace, UK
Age: 30
Nick R is on a distinguished road
Send a message via MSN to Nick R Send a message via Yahoo to Nick R
Status: Offline Default
and it does work :p

....

eventually.....

if your not me....

Last edited by Nick R; 07-25-2006 at 08:26 PM.
Reply With Quote
Old 07-26-2006, 07:39 AM   #3
Nick R
vBulletin Guru

Nick R's Avatar

Activity Longevity
0/20 13/20
Today Posts
0/3 sssss4450
Location: Cyberspace, UK
Age: 30
Nick R is on a distinguished road
Send a message via MSN to Nick R Send a message via Yahoo to Nick R
Status: Offline Default
if anyone wants a working example to play with just ask
Reply With Quote
Old 08-28-2006, 01:30 PM   #4
Idan
Coder
Idan's Avatar

Activity Longevity
6/20 17/20
Today Posts
0/3 sssss1482
Location: Israel
Age: 29
Idan is on a distinguished road
Status: Offline Default
very good tutorial m8, both here and @ vb.org.

i got 1 question regarding the ajax involved with the quickreply.
when doing a quick reply, from what i've seen it's sends data to the bottom of showthread page. suppose i would want to change (remove some box with text & replace it with another box with test) something @ top of showthread page (after quick reply), since there is no refresh - any code i put under some showthread_*** hook doesn't seem to work.
can u help with some ideas to get this one done ?
Regards,
Idan.

* Support will only be given via forums !
* If this post solved/aided your problem, please click "mark as aid" / "mark as solution" as explained in here
Reply With Quote

Reply

« [How-to] Correct the missing WOL location for the activity addon stats | [How-To] php: fetch specific info from remote + intro to regexp »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Merge Nick R vBulletin Modification Requests 0 07-05-2006 04:14 PM



All times are GMT. The time now is 05:03 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Transverse Styles
  • Top
  • Archive
  • vBSEO
  • Contact Us
LinkBack
LinkBack URL LinkBack URL
About LinkBacks About LinkBacks
Bookmark & Share
Digg this Thread! Digg this Thread!
Add Thread to del.icio.us Add Thread to del.icio.us
Bookmark in Technorati Bookmark in Technorati
Furl this Thread! Furl this Thread!