Go Back   vBulletin Setup > Software & Tech > vBulletin

Reply
 
LinkBack Thread Tools Display Modes
Old 11-22-2006, 07:40 AM   #1
vBulletin Owner
Feedback Score: 0 reviews
 
Join Date: Nov 2006
Posts: 40
TECK
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 vb 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   Reply With Quote

Advertisement [Remove Advertisement]

Reply
vBulletin Setup > Software & Tech > vBulletin


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[vB News] Some answers to important licensing questions Industry News vBulletin 0 11-02-2009 07:05 AM
[vB News] vBulletin China Industry News vBulletin 0 11-01-2009 01:01 PM
[vB News] New Blogs Concerning vB4 Industry News vBulletin 0 10-30-2009 02:05 PM
I'm in New York! PandaMarketer Off Topic 3 08-13-2009 04:43 PM
Play Free Arcade Games Tolstoy Buy and Sell 0 03-03-2006 11:51 PM


All times are GMT +1. The time now is 09:30 AM.

Inactive Reminders By Mished.co.uk and FTP-Anime.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133