Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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! (:

share|improve this question

3 Answers

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.

share|improve this answer
 
Ah, nice catch. I'll fix that- my fault. –  Joe Aug 1 '10 at 5:22

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

share|improve this answer
 
Just did that. Did I do it right? :P (json_encode, that is..) –  Joe Aug 1 '10 at 6:00
 
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 Aug 1 '10 at 12:49

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.