Trying to get a value from returned json/curl response

Hi
I'm querying edmunds.com with a vin to decode. I'm using a curl request, looks like this:
$api_key = "mykeyhere";
$vin = myvin;


$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://api.edmunds.com/v1/api/toolsrepository/vindecoder?vin='.$vin.'&fmt=json&api_key='.$api_key.'',
    CURLOPT_HEADER => 'false'
));

$data = curl_exec($curl);

echo $data;

curl_close($curl);

Open in new window

Its returning below (this is partial sample).
{"styleHolder":[{"id":101076433,"makeId":200009788,"year":2009,"makeName":"Dodge","makeNiceName":"dodge","modelId":"Dodge_Nitro","modelName":"Nitro","modelNiceName":"nitro","modelYearId":100525935,"transmissionType":"AUTOMATIC","engineType":null,"engineCompressorType":"NA","engineFuelType":"regular unleaded","engineCylinder":6,"engineSize":3.7,"trim":{"name":"SLT","niceName":"slt"

Open in new window

I'm trying to get the 'year' for example to populate a text input. Looks like this:
	$( "#getvin" ).click(function() {
	$.post("response.php",{ vin: $('input[name="vin"]').val() },
	function(data){
      $('#vehicleinfo').show();
      $('input[name="year"]').val(year);
	});
  });

Open in new window


Problem is my input field is getting populated with this:
[object HTMLInputElement]

instead of 2009 as in the json above.

Any idea where I'm off?
LVL 1
tjyoungAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
test page : http://jsfiddle.net/rqvvs/1/
 $( "#getvin" ).click(function() {
            $.post("response.php",{ vin: $('input[name="vin"]').val() },
                    function(data){
                        $('#vehicleinfo').show();
                        $('input[name="year"]').val(a.styleHolder[0].year);
                    });
        });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Add the json paramete to the .post call
$( "#getvin" ).click(function() {
    $.post(
        "response.php",
        { vin: $('input[name="vin"]').val() },
	function(data) {
            $('#vehicleinfo').show();
            // Reference the value returned from the .post - data to get to the year
            $('input[name="year"]').val(data.styleHolder[0].year);
    },
    'json'); // ADD THIS
  });

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.