The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Intergrating 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 intergrate AJAX technology into modifictions. 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 recieve any data returned with no reloading, so if you're thinking of intergrating AJAX then you must first have a scenario where you wish to push data and recieve it, recieval 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 recieved 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); 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 recieves data, an example is below: Code:
My_AJAX_Object.onreadystatechange(My_AJAX_Reciever); 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 recieved successfully\n\n' + My_AJAX_Object.handler.responseText) } } Step 3 - Firing And Recieving 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'); 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); PHP Code:
PHP Code:
Quote:
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 https://vborg.vbsupport.ru/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 |
#12
|
|||
|
|||
First, thank you for this tutorial, very helpful.
You forgot to put one key world in your javascript code : handler So this code : Code:
function My_AJAX_Reciever() { if (My_AJAX_Object.readyState == 4 && My_AJAX_Object.status == 200 && My_AJAX_Object.responseText) { alert('Data recieved successfully\n\n' + My_AJAX_Object.responseText) } } 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 recieved successfully\n\n' + My_AJAX_Object.handler.responseText) } } |
#13
|
|||
|
|||
I did the code above but it didn't work at first.
I changed the $_POST to $_GET then I passed test.php?do=ajax&pagevar=rrr in the address bar and it worked. But using $_GET is insecure. Can someone make a small working example like a simple chat? |
#14
|
|||
|
|||
look at vbshout
its like a simple chat |
#15
|
|||
|
|||
the missing .handler. should really added to the first posts example
|
#16
|
|||
|
|||
this was very useful, thanks
|
#17
|
|||
|
|||
yes it's great start to integrate own ajax things.. I used rico.js but looks like it creates problems with some vb javascript so I change everything to vb-ajax now
|
#18
|
|||
|
|||
For the JavaScript written in post 7 by " LiveWire " how can we add auto refresh so every 5 min it will check certain variables in a PHP file if its exist then small popup will shown if no nothing will happen and all of this will happen without the manually refresh.
|
#19
|
|||
|
|||
so for the:
PHP Code:
PHP Code:
|
#20
|
|||
|
|||
Yes.
|
#21
|
|||
|
|||
PHP Code:
What should i use for onclick?: eg <a href='#' onclick='return Who knows'>Refresh</a> DOES ANYONE HAVE A WORKING EXAMPLE OF THIS? |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|