/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] help with a simple ajax / xajax example

so I am very new to ajax and i will confess that I am not the most brilliant javascript programmer in the world, but I am trying to learn.

i know some php, so I figured I would use xajax for the ajax stuff, which seems to be a lot less coding than using stuff like rico and whatnot.

anyways, i am trying a small example, and the example is basically to be able to display the current system date as a link, and whenever you click the link, the link automatically updates to the new system time without reloading the entire page.

here is what i have tried:

[CODE]
<HTML>
<HEAD>
<?php
require_once(‘./xajax/xajax.inc.php’);

function updateDate()
{
$output = shell_exec(‘date’);
$objResponse = new xajaxResponse();
$objResponse->addAssign(“date_link”, “innerHTML”, $output);
return $objResponse;
}

function processView()
{
$output = shell_exec(‘date’);
$a = “<a href=”#” onclick=”xajax_updateDate();” id=”date_link” name=”date_link” title=”Check the time”>$output</a>”;
return $a;
}

$xajax = new xajax();
$xajax->registerFunction(“updateDate”);
$xajax->processRequests();
$xajax->printJavascript(‘./xajax/’);
?>
</HEAD>
<BODY>
<?php echo processView(); ?>
</BODY>
</HTML>
[/CODE]

the error I am receiving is:

[CODE]
Error: the XML response that was returned from the server is invalid.
Received:
<HTML>
<HEAD>
<?xml version=”1.0″ encoding=”utf-8″?><xjx><cmd n=”as” f=”date_link” p=”innerHTML”>
<![CDATA[Fri Dec 29 09:04:58 CST 2006]]></cmd></xjx>
[/CODE]

does anyone know what I am doing wrong. I have examples of what to do if I am using some sort of button, but I have yet to find anything that shows how to update a link. what do you put in the href attribute? the onclick?

thanks for any help. im sure it is something trivial and stupid.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cornercuttinauthorDec 29.2006 — fixed.

basically, i needed to reorder my code, which makes sense, but earlier i was getting a whitespace error, so that is why it looked like it did.

anyways, this works. so if you want an easy example on how to update a link via ajax / xajax / php, this works:
[CODE]
<?php

require_once('./xajax/xajax.inc.php');

function updateDate()
{
$output = shell_exec('date');
$objResponse = new xajaxResponse();
$objResponse->addAssign("date_link", "innerHTML", $output);
return $objResponse;
}

function processView()
{
$output = shell_exec('date');
$a = "<a href="#" onclick="xajax_updateDate();" id="date_link" name="date_link" title="Check the time">$output</a>";
return $a;
}

$xajax = new xajax();
$xajax->registerFunction("updateDate");
$xajax->processRequests();
?>
<HTML>
<HEAD>
<?php
$xajax->printJavascript('./xajax/');
?>
</HEAD>
<BODY>
<?php echo processView(); ?>
</BODY>
</HTML>
[/CODE]
×

Success!

Help @cornercuttin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...