/    Sign up×
Community /Pin to ProfileBookmark

Can AJAX access PHP classes?

I’m trying to take input from a text field and use it to update data member $FavoriteColor using the member function ChangeColor($NewColor); without a page reload. Is AJAX equipped to access PHP classes?

Here’s the example class:

[code=php]
<?php

class TestClass
{
public $Name = “Joe”;
public $FavoriteColor = “Green”;

public function ChangeColor($NewColor)
{ $this->FavoriteColor = $NewColor; }

public function ShowInfo()
{ echo $this->Name . “‘s favorite color is ” . $this->FavoriteColor; }
}

$obj = new TestClass();
$obj->ChangeColor(“red”);
$obj->ShowInfo();
//output is “Joe’s favorite color is red”
?>

<input type=”text” id=”color”>
<input type=”button” onclick=”UpdateColor();” id=”submit”>
[/code]

Theoretically, UpdateColor() would do this…
-Dave

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 15.2009 — It's not really a case of AJAX being equpped. All AJAX does is make a request to your server and return the result without having to reload the browser. So anything your server can serve up to a normal browser request can be handled by an AJAX request. So as long as your script can return the desired result to a synchronous request (ie accessing normally through the browser) it will be able to return the same during an asynchronous request (ie using AJAX).
×

Success!

Help @KingCobra220 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.17,
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,
)...