jQuery $.post processing JSON response

后端 未结 3 2043
眼角桃花
眼角桃花 2020-12-06 10:21

I\'m having trouble figuring out how to properly read my JSON response from a jQuery $.post() request.

In the below jQuery code, I populate an associative array of s

3条回答
  •  我在风中等你
    2020-12-06 10:26

    Ok then..the data object you're getting back from the post is: {"id":"abc","images":[{"color123":"somelink.com\/123","color223":"somelink.com\/‌​223"}]};

    If you change your alert, you'll find the values you're looking for:

    $.post(
        "test.php",
        { id: product_id, "images[]": jQuery.makeArray(image_links) },
        function(data) {
            var response = jQuery.parseJSON(data);
    
            var images = response.images[0];
            for (var i in images){
                alert(images[i]);
            }
        }
    );
    

提交回复
热议问题