1

here is my ajax request :

 $(".colorme").on("click", function () {
        var c = $(this);
        var b = "id=" + c.attr("id");

    $.ajax({
        type: "POST", 
        url: "../../colorme",
        data: b,
        success: function (a) {
                   $.when(c.fadeOut(300).promise()).done(function () {

            if (c.hasClass("btn")) {

                c.removeClass("btn-default").addClass("btn-success").text(a).fadeIn()

            } else {
                c.replaceWith('<span class="notice_mid_link">' + a + "</span>")

            }
        })
        }});
        return false
    })

so here is what I receive as a response :

{"f0d8c0":0.3269616519174,"d8d8d8":0.22377581120944,"181818":0.10926253687316,"d8a890":0.091268436578171,"303030":0.054454277286136}

I would like to be able display each one of those values as a pair.Right now it returns :[object OBJECT]

1

3 Answers 3

1

Use,

data = $.parseJSON(JSON.stringify(a));
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.

var obj = jQuery.parseJSON(a);
alert( obj.f0d8c0);
alert( obj.d8d8d8);

You can assign your response value in var a =$.parseJSON(RESPONSE VALUE)

For more Details Read this LINK

Comments

0
$.ajax({type: "POST", url: "../../colorme", data: b, success: function (a) {

  resp = jQuery.parseJSON(a);
  alert(resp.f0d8c0);
  alert(resp.d8d8d8); //maybe you need to use a better way to name the data?

               $.when(c.fadeOut(300).promise()).done(function () {

        if (c.hasClass("btn")) {

            c.removeClass("btn-default").addClass("btn-success").text(a).fadeIn()

        } else {
            c.replaceWith('<span class="notice_mid_link">' + a + "</span>")

        }
    })
    }});

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.