1

I am passing data from php in json format, how do I access it?

This is the result:

{"solctype":"Long Term Agreement","checkbox":"1","prnumber":"356363563"}

I have tried

$.post("getgrid?id="+id,
{
},
function(data, status){
 console.log(data.solctype);
});

This always returns undefined

Matt Ellen
11.6k5 gold badges74 silver badges94 bronze badges
asked Aug 15, 2016 at 11:55

1 Answer 1

1

You need to parse the string data and convert it to a JavaScript object.

Use something like this:

 var stringData = {"solctype":"Long Term Agreement","checkbox":"1","prnumber":"356363563"};
 var parsedData = JSON.parse(stringData);
 console.log(parsedData.solctype)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

answered Aug 15, 2016 at 11:57
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.