/    Sign up×
Community /Pin to ProfileBookmark

Problem with ajax and objects

I’m trying to write a object for an admin page. It usage should be real simple. Like

var u = new User();
u.openUser(user_id);
alert(u.user_name); etc.

I create a xmlhttp response object in the openUser function and retrive the data works fine.
The problem i have is that the ajax response function seams to drop its knowing if it own object.

ex;

[CODE]function User()
{
//Public parameters
this.user_id = 0;
this.user_name = “”;

//Public methods
this.openUser = c_user_openuser;

//Open user Function
function c_user_openuser(user_id)
{
//Sends the open user requesst to the server.
var url = “engine/xml_user.php”;
var pars = {
action: ‘open’,
user_id: user_id
};
//Request user XML from server
p_this.ajax = new Ajax.Request(url,
{
method: ‘get’,
parameters: pars,
asynchronous: true,
onComplete: c_user_showResponse
});
// Process (User) HTTP response and update the object
function c_user_showResponse(xmlHttpRequest, responseHeader) {
$(‘dumpzone’).value = xmlHttpRequest.responseText;

//Check if response is a valid xml
if(xml_validate(xmlHttpRequest,$(‘d_return’)))
{
var xmlDoc = xmlHttpRequest.responseXML;
rNode = xmlDoc.getElementsByTagName(“user”)[0];
//Assining parameters from XML
this.user_name = getNodeValue(rNode.getElementsByTagName(“name”));
}
else
{
alert(“Not a valid xml”);
}
}
}
}
[/CODE]

problem is that u.user_name returns nothing…

I’m using protorype at this expample, and some outside functions (they all work so thats not the problem). I get the same error when i do it from scratch.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NatdripMay 09.2007 — if you are not getting anything the chances are that your php page is not correctly responding.

check your response object

[CODE]alert(xmlHttpRequest.responseText)[/CODE]
Copy linkTweet thisAlerts:
@ztripezauthorMay 09.2007 — That part is working just fine...
×

Success!

Help @ztripez 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...