Mario Hu
Mario Hu

Reputation: 77

how can I get the value from json?

I have this json: {message:"a"}

I send the request by ajax and then get the response:

<script>
        $(document).ready(function(){
            $("#l").click(function(){
                $.ajax({
                    url:"index/judement",
                    type:"POST",
                    dataType:"json",
                    contentType:"application/json;charset=UTF-8",
                    data:JSON.stringify({
                        number:$("#number").val(),
                        password:$("#password").val()
                    }),
                    success: function (data) {
                        alert(JSON.stringify(data));
                    },
                    error: function () {
                      alert("...");
                    }
                });
            });
        })
    </script>

And then I get this: enter image description here but I just want to get a!! not all the json! how should I do?

Upvotes: 0

Views: 43

Answers (2)

Saurabh Agrawal
Saurabh Agrawal

Reputation: 7739

try this remove JSON.stringify() so that you will get value as object not as string

Try this

alert(data.message);

This will only alert a,

if you will use

alert(JSON.stringify(data.message));

it will alert "a"

Upvotes: 1

Sachin Gupta
Sachin Gupta

Reputation: 8358

try this:

alert(JSON.stringify(data.message));

Upvotes: 0

Related Questions