user3715910 user3715910 - 1 year ago 106
jQuery Question

parse json using ajax success function

I'm trying to display the json that i get and parse it in the success function of ajax.

What I have so far:


data = "Title=" + $("#Title").val() + "&geography=" + $("#geography").val();

url= "/portal/getResults.php";

url: url,

type: "POST",
//pass the data
data: data,
dataType: 'json',

cache: false,
success: function(data) {



getResults.php (JSON output):


"results": [
"DocId": 2204,
"Title": "Lorem ipsum dolor sit amet, consectetur",
"Locations": [
"State": "New York",
"City": ""
"State": "New York",
"City": "New York City"
"Topics": [
"PublicationYear": "2011",
"Organization": "New Yorks Times",
"WebLocation": "",
"Description": "Lorem Ipsum"
"TotalMatches": 1


I expect the result in data to be the the json from getResults.php but instead I get [object Object].

I have also tried the code below but get no response:

success: function(data) {
var json1 = JSON.parse(data);

Answer Source

since you're telling jQuery that you want dataType:'json', the ajax function parses the JSON response into an object for you. the result object you see should be an object with data matching the JSON response from your server. if you need the string version, try JSON.stringify(), otherwise you can just use the object as is: data['results'][0]['DocId'], etc

good luck!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download