0

I am trying to get the data from the array in foreach . I am sending a ajax get request to php file and get response with json & array. But when I try to print what inside the array its broke..

My JS code:

        var url = $("#url").val();
        var type = 'F';
        var data_url = url + "manage/sources/ajax/ajax.php?type=GetBarber&gender=" + type ;
        $.ajax({
            type: "GET",
            url: data_url,
            dataType: "json",
            success: function (response) {
             // response returning - > {"status":"success","data":["name541","name214"]}
            var json_obj = $.parseJSON(response);
             for (i=0; i < json_obj.data.length; i++)
                  {
                    var payment = json_obj.data[i];
                    console.log(payment); // Just for debugging
                  }


                }
                }); 

I am trying to print what inside the data (names..) Thank you for help

1 Answer 1

2

You have the dataType set to json therefore response is already parsed to an object. So do not call $.parseJSON

for (i=0; i < response.data.length; i++)
{
    var payment = response.data[i];
    console.log(payment); // Just for debugging
}
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.