Alvin
Alvin

Reputation: 8499

AJAX POST JSON value

I have AJAX POST, the result is JSON:

$.ajax({
  type: "POST",
  url: "../../api/test",
  data: JSON.stringify(source),
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (result) {
    var upload = JSON.stringify(result);
    console.log(upload);
  }
});

The upload result is:

{"Link":0,"Title":"d","Description":"dada","Keywords":"dad"}

How can I get the value of Title?

Upvotes: 0

Views: 148

Answers (2)

rand0m
rand0m

Reputation: 851

As you already have JSON string, It's simple as a pie! All you need to do is to call the property you want from the variable you assigned your result to.

for example:

var post_response;
$.ajax({
    type: "POST",
    url: "../../api/test",
    data: JSON.stringify(source),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (result) {
        post_response = JSON.stringify(result);
        console.log("Title: "+post_response.Title);
    }
 });

hope this helps.

Upvotes: -1

igor
igor

Reputation: 2916

Do not stringify the result, just use result.Title.

Upvotes: 3

Related Questions