Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

jquery ajax php json fetch -- help...

Hi I'm trying to get the data I fetch using PHP.

the page is named twitter-fetch.php

now what I know is, that page is now filled with json data converted to associative array because I json_decode() on the the data. (please correct me if I'm wrong).

now what I'm trying to do is calling that page using ajax.

the name of the project is phone. the my js file is in the js folder. and the twitter-fetch.php is in php folder. I just want to see the result in console for now, help... :(

I'm still new to ajax and json so I'm really not sure on what I'm doing here

      $.ajax({
        url: '/phone/php/twitter-fetch.php',
        type:'POST',
        contentType: 'application/json',
        dataType: 'json',
        success: function(result){
            console.log(result);
            alert('success!');
        }
      });
     });


this the php line where I used the json_decode and stored it in $string

    $string = json_decode($twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest(),$assoc = TRUE);

1 Answer

I'm quite sure the problem is in the URL. Check it according to where the index.php file is coming from.