views:

64

answers:

3

Alright, this pretty much goes along with my previous question. I'm still trying to figure out how to display data from an array which is created by a PHP file- using JS/jQuery. I'm working on a points system for ZetaBoards, and I've currently got it set up here. (Points will be displayed below the users post count once I get this working.. you guys can't see the +/- functions which work fine, haha. :p )

http://outlinetokens.hostei.com/scripts/output.php

So, for each user- I can get their user ID, I just don't know how to check if their name is in the array. (and if it is, display their points) I'm guessing I'll have to do something like this? Here's the chunk of the code that deals with this.. you'll see where I need help.

if (location.href.match('/topic/')) {
    $.getScript('http://outlinetokens.hostei.com/scripts/output.php', function () {
        $('td.c_username a.member').each(function () {
            value = 0;
            u = $(this).attr('href').split('profile/')[1].split('/')[0];

            // this is where I need to do the 'search.' Just a basic guess.. help. D:

            if (values.uid == u) {
                value = values.points;
            }

            $(this).parents('tr').next().find('dl.user_info').append('<dt>' + options.system_name + ':</dt><dd class="Points"><span id="point_total">' + value + '</span></dd>');
        });
    })
}

...in case the code tag screwed it up:

http://ryjoe.pastebin.com/raw.php?i=0bsZNnVq`

Thanks! (:

+1  A: 

I'm not sure if I'm reading your question right, but you can load JSON with jQuery, instead of a script.

If then, the array is one of usernames, you can just use response.hasOwnProperty(username) or similar to check if it's in the JSON object you got back

Also, in php use json_encode

jeremiahd
Just did that. Did I do it right? :P (json_encode, that is..)
Joe
Uh, I can't see your php, so I don't really know, but it looks like valid json, so probably. You just feed it an object, and it spits out JSON.
jeremiahd
+2  A: 

Why are these lines in your data formatted like this:

{'uid','342230','name','Joe','points','250'}

instead of this:

{'uid': '342230', 'name': 'Joe', 'points','250'}

If that was formatted correctly you could access the properties.

spinon
Ah, nice catch. I'll fix that- my fault.
Joe
A: 

You want JQuery.parseJSON. Load the data string, parse it, and assuming its valid JSON, it will become a JS object. Then just access the members in the usual way.

Charlie Martin