Forum Moderators: open

Message Too Old, No Replies

Change image after getting XML Response.

         

v01and04

5:30 pm on Feb 1, 2008 (gmt 0)

10+ Year Member



I have a "add artist to watch list" image link which sends a value to the Preference Center and returns the following XML response:

<prefCenterOp>
<status>success</status>
<recordCount>1</recordCount>
</prefCenterOp>

I would like to change the image after it's clicked, depending on the value of <recordCount>1</recordCount>. It can either be "1" or "0"

So say I have image: 1a.jpg, when the user clicks it and XML returns recordcount 1, that image needs to change to 2a.jpg

How should I go about pulling this off?

Thanks!

cmarshall

5:43 pm on Feb 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

You'd probably read the XML with JS [quirksmode.org], then switch on that.

I don't have any experience doing that, myself, simply because I always resolve XML to JSON [json.org] on the server, using PHP XML [us.php.net] or PHP XSLT [us.php.net], which is another possibility.

Actually, that XML is so simple you could probably use a JavaScript Regex to parse it. JS has good RegEx support [developer.mozilla.org].

httpwebwitch

1:16 am on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



erk! - JS has mediocre Regex support - just enough to find and replace simple patterns. It's horrid at backreferences, and only allows 10 "captured" matches in a string.

but in this case? cmarshall is right, you'll be able to quickly grab that value by running the whole XML through a regex. once you have that little data element in a variable, you're one "if()" statement away from the solution