Go Back   vBulletin Modification Discussions > Coding Discussions > PHP Discussions, Tutorials and Help
Home Register FAQ Members List Calendar Mark Forums Read
vBSEO Info Tags

About This Page: This is a discussion on Ajax code... pain. Some help is much apreciated. within the PHP Discussions, Tutorials and Help forums, part of the Coding Discussions category, at vBulletin Modification Discussions. Hi all, I really need your help on a piece of DOM code. Basically, what I need to do is create a piece of code that will grab an existing link, verify it's value into database and if it


Reply
 
LinkBack Thread Tools
Old 11-21-2006, 11:40 PM   #1 (permalink)
Junior Member
 
Join Date: Nov 2006
Posts: 16
TECK is on a distinguished road
iTrader: (0)
Ajax code... pain. Some help is much apreciated.

Hi all,

I really need your help on a piece of DOM code.
Basically, what I need to do is create a piece of code that will grab an existing link, verify it's value into database and if it changes, to update the data into the existing table cell.
The process is similar to the vBulletin IP resolve code.

Let me show you what I did so far. The HTML code looks like that:
Code:
<table id="weekdays_{$month}" cellpadding="$stylevar[cellpadding]" cellspacing="0" border="0" width="100%">
<tr>
	<td id="actual_{$eventid}" class="$bgclass espace" id="refresh_$eventid" style="text-align: right;" nowrap="nowrap">
		<if condition="$show['pendingevent']">
			<a id="actual_{$eventid}" href="calendar.php?do=refreshdata&amp;e={$eventid}&amp;actual=pending">
				<img alt="$vbphrase[product_refresh]" border="0" class="inlineimg" src="$stylevar[imgdir_misc]/calendar_tool_refresh.gif" width="16" height="16" />
			</a>
		<else />
			<span class="$event[actualkey]" style="float: right;">$event[actual]</span>
		</if>
	</td>
</tr>
</table>
<script type="text/javascript" src="clientscript/vbulletin_ajax_refreshdata.js?v=$vboptions[simpleversion]"></script>
<script type="text/javascript">
<!--
vB_AJAX_RefreshData_Init('weekdays_{$month}');
//-->
</script>
If we find the value 'pending', the vBulletin template will display an image, else, we display the actual value found, ie. 'extra-light'.
See $show[pendingevent] conditional.

Now, the PHP code that triggers all this is:
Code:
if ($_REQUEST['do'] == 'refreshdata')
{
	// init the XML code
	require_once(DIR . '/includes/class_xml.php');
	$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');

	// if we have a valid ID
	if ($vbulletin->GPC['eventid'])
	{
		// define the database field
		$event['fields'] = unserialize($eventinfo['customfields']);
		// this could be 'pending' or 'new-value'
		$event['actual'] = vbstrtolower($event['fields'][25]);
		// this is the 'pending' word
		$event['actualphrase'] = vbstrtolower($vbphrase['product_pending']);

		// if we deal with ajax
		if ($vbulletin->GPC['ajax'])
		{
			// if the database value is not 'pending'
			if ($event['actual'] != $event['actualphrase'])
			{
				// we need to fire the AJAX code here
				// first help needed here
			}
		}
	}
	else
	{
		// bad ID
		$xml->add_tag('error', 'invalidid');
	}

	// end XML code
	$xml->print_xml();
}
And now, the AJAX .js file:
Code:
function vB_AJAX_RefreshData_Init(tableid)
{
	if (AJAX_Compatible && (typeof vb_disable_ajax == 'undefined' || vb_disable_ajax < 2))
	{
		var link_list = fetch_tags(fetch_object(tableid), 'a');
		for (var i = 0; i < link_list.length; i++)
		{
			if (link_list[i].id && link_list[i].id.substr(0, 7) == 'actual_')
			{
				link_list[i].onclick = refresh_data;
			}
		}
	}
}

function vB_AJAX_RefreshData(actual, objid)
{
	this.actual = actual;
	this.objid = objid;
	this.xml_sender = null;

	var me = this;

	this.resolve = function()
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('calendar.php?do=refreshdata&actual=' + PHP.urlencode(this.actual), 'do=refreshdata&ajax=1&actual=' + PHP.urlencode(this.actual));
	}

	this.onreadystatechange = function()
	{
		// need help here
	}
}

function refresh_data(e)
{
	var refresher = new vB_AJAX_RefreshData(this.innerHTML, this.id);
	refresher.resolve();
	return false;
}
I apreciate the time you take to help me with this matter.
Thanks.

EDIT: I included a .txt file with all the code, you you can follow better everything.
Attached Files
File Type: zip code.zip (1.4 KB, 0 views)
TECK is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links

Reply
Tags: , , , ,





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

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

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


A vBSkinworks Design Recoded By vBModder.
All Code Distributed On This Site is © 2006 by it's author.
Search Engine Optimization by vBSEO 3.1.0

All times are GMT -7. The time now is 07:55 AM.
Online Users 78
Registered 1
Guests 77
Members 3141
Active Members 225
Threads 1574
Posts 6981
Top poster: Code Monkey (2193)
Welcome to our newest member, Stutoman
Most users ever online was 235, 04-11-2007 at 08:59 AM.
Speak Out! vBulletin gets the web talking!


vBulletin Setup SEO

vBulletin graphics resource images