1

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!

10
  • Are you actually specifying application/json (or whatever the cool kids use) as the content type? Commented Jun 21, 2013 at 1:41
  • What error did you get? Commented Jun 21, 2013 at 1:41
  • I am getting a syntax error when I have dataType json, please refer to my previous post, stackoverflow.com/questions/17226224/… Commented Jun 21, 2013 at 1:43
  • @cHao how do I specify it? thanks for the reply guys Commented Jun 21, 2013 at 1:43
  • 1
    have you echo the json_encode array in sort_skill_be.php? Commented Jun 21, 2013 at 2:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.