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

Hello I was wondering if this is possible?

$results = $stmt->fetchAll();
    $recent_posts = array();
    foreach ($results as $row){
        $post = array(
            'username' => $row['username'],
            'steam' => $row['steam'],
            'skill' => $row['skill'],
            'description' => $row['description'],
            'date' => $row['date'],
        );
        array_push($recent_posts, $post);
    }
    return json_encode($recent_posts);

If this is possible how exactly do I access it in jquery? $

('#order_by').on('change', function(){ 
        $.ajax({ 
            type: "POST", 
            url: "sort_skill_be.php", 
            data: { skill: this.value }, 
            error: function (qXHR, textStatus, errorThrown) { 
                console.log(errorThrown); 
                //alert(errorThrown);
            }, 
            success: function (result) { 
                alert(result[0].skill);  // CAN I ACCESS IT LIKE THIS?
            } 
        }); 
    }); 

This is what I have so far, but I keep getting weird errors. When I added datatype:json I keep getting problems. So I feel I am handling this incorrectly, Thank you for the help!

share|improve this question
Are you actually specifying application/json (or whatever the cool kids use) as the content type? – cHao Jun 21 at 1:41
What error did you get? – xdazz Jun 21 at 1:41
I am getting a syntax error when I have dataType json, please refer to my previous post, stackoverflow.com/questions/17226224/… – Austin Truong Jun 21 at 1:43
@cHao how do I specify it? thanks for the reply guys – Austin Truong Jun 21 at 1:43
1  
have you echo the json_encode array in sort_skill_be.php? – 蒋艾伦 Jun 21 at 2:52
show 5 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.