1

Hi guys this is result array from ajax response

[{"qty":1,"name":"7-test-Professional","part_number":"12231","list_price":"800"},
{"qty":1,"name":"Senior Professional Forester","part_number":"","list_price":"97.000000"]

where i am trying to alert each value as

$.ajax({
    type: 'POST',
    url: 'getdata.php?product_id='+rate_id,
    success: function(data)
    {    
        // console.log(result);
        result=$.parseJSON( data );
        $.each(result, function( index, value ) {
            alert( index + ": " + value );
        });
        //alert(result); //this prints the above array !!               
    }
});

getting output as : index_value: [object Object]

Thanks for your time.. :)

3
  • alert( index + ": " + JSON.stringify(value));? Commented Oct 9, 2017 at 17:13
  • Thanks its printing as 0: {"qty":1,"name":"7-test-Professional Forester Hour","part_number":"1231231","list_price":"800.000000","sale_price":"800.000000","total_price":"800.000000"} to get individual i should use value.qty right? Commented Oct 9, 2017 at 17:16
  • its working great!! thanks raina77ow :) Commented Oct 9, 2017 at 17:18

1 Answer 1

1

Try adding dataType: 'json' into your ajax parameters
You wouldn't need parseJSON I hope.

The final code becomes

       $.ajax(
          {
            type: 'POST',
            url: 'getdata.php?product_id='+rate_id,
            dataType: 'json',
            success: function(data)
            {    
              $.each(result, function( index, value ) {
                   alert( index + ": " + value );
              });           
            }
        });
Sign up to request clarification or add additional context in comments.

Comments

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.