0

i am getting this response after ajax post

Array
(
    [curve] => Array
        (
            [0] => stdClass Object
                (
                    [date1] => 2018

                    [total1] => 0
                )

            [1] => stdClass Object
                (
                    [date1] => 2018

                    [total1] => 200
                )

            [2] => stdClass Object
                (
                    [date1] => 2018

                    [total1] => 0
                )

            [3] => stdClass Object
                (
                    [date1] => 2018

                    [total1] => 0
                )

            [4] => stdClass Object
                (
                    [date1] => 2018

                    [total1] => 0
                )

        )

)

and my post request is as below:

$.post("<?=base_url();?>app/total_meter_feeder_r_curve", { divid: divid,id:id}, function(result)
            {
                alert(result);
                        $('.basefp').hide();

                        // chart.series[0].setData([first,second]);
            });

i want to retrieve value on ajax success of "total1" only . how could i achieve this. on alerting result i am getting the above array.

2
  • You need to use $.each method of jquery like $.each(result, function(index, value) { alert(value); }); Commented Jun 8, 2018 at 12:36
  • result.curve[0]->total1, arrow is used for accessing stdClass Object. I haven't tested the code though. Commented Jun 8, 2018 at 12:40

1 Answer 1

4

So basically you have got result in response of ajax success , result variable is array of objects. Hence Now you have to travel into this array, so the total1 is a variable in one of object in array of result['curve'].

If you try below snippet your problem should get resolve:

jQuery.each(result['curve'], function(index, value) { 
        alert(value.total1); 
});
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.