Reputation: 192
I am attempting to update page content on a mobile version of a desktop site by making an Ajax call back to the desktop version. The mobile version of the site lives on a dedicated subdomain, and page content from the desktop versin of the site is being packaged as JSON. The Ajax call is successful, because I am able to log out the JSON object in the console. However, I am unable to isolate the specific part of the JSON object (labeled "content" within the object). The function I've written will not place anything on the page (although it will place other HTML on the page, ruling out that there is something wrong with the function itself), and attempts to log the "content" portion of the JSON object specifically in the console returns "undefined." The code that I'm using for the entire process is this:
function processJSON(url, id){
$.ajax({
url: url,
data: {get_param : 'content'},
success: function(response){
$(id).html(response.content);
},//ends success
dataType: 'json',
});//ends ajax
};//ends processJSON
The arguments for the function are as follows: "url" is the url of the JSON feed (set equal to a variable, usually), and "id" is the id of the div in which I am attempting to place the HTML of the "content" portion of the JSON object.
The JSON response is as follows:
{"status":"ok","page":{"id":9,"type":"page","slug":"scenes","url":"http:\/\/www.davidcharlesbrown.com\/scenes\/","status":"publish","title":"Scenes","title_plain":"Scenes","content":"<h3>I’ve always been wrapped up in the magic of the stage.<\/h3>\n<p>When I was a junior in high school, I was cast in a chorus role of my first play. I froze as I was about to make my first entrance in front of an audience of several hundred people. The person behind me pushed me on stage, which was the kindest thing he could have done.<\/p>\n<p>Since then, I’ve been involved in over 100 productions in semi-professional, educational, community, and faith-based settings. I write, direct, design, and occasionally even act. I’ve also taught acting methods.<\/p>\n<p>I’m currently a member of the Autism Theatre Network, through the <a href=\"http:\/\/www.appliedtheatrecenter.org\/autismnetwork.html\" target=\"_blank\">Applied Theatre Center<\/a>. I’m involved with an agency that uses theatre to teach social pragamatics to children, adolescents, and young adults who are on the Autism spectrum.<\/p>\n<p>It’s a stage of a different sort.<\/p>\n","excerpt":"<p>I’ve always been wrapped up in the magic of the stage. When I was a junior in high school, I was cast in a chorus role of my first play. I froze as I was about to make my first entrance in front of an audience of several hundred people. The person behind me pushed [...]<\/p>\n","date":"2013-04-10 14:08:27","modified":"2013-04-16 17:34:18","categories":[],"tags":[],"author":{"id":1,"slug":"truthscribe722gmail-com","name":"David Brown","first_name":"David","last_name":"Brown","nickname":"REDACTED","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"open","custom_fields":{}}}
Thanks!
Upvotes: 1
Views: 86
Reputation: 97672
content
is not at the root of the object , it is in the page property.
$(id).html(response.page.content);
see
{
"status": "ok",
"page": {
"id": 9,
"type": "page",
"slug": "scenes",
"url": "http://www.davidcharlesbrown.com/scenes/",
"status": "publish",
"title": "Scenes",
"title_plain": "Scenes",
"content": "<h3>I’ve always been wrapped up in the magic of the stage.</h3>\n<p>When I was a junior in high school, I was cast in a chorus role of my first play. I froze as I was about to make my first entrance in front of an audience of several hundred people. The person behind me pushed me on stage, which was the kindest thing he could have done.</p>\n<p>Since then, I’ve been involved in over 100 productions in semi-professional, educational, community, and faith-based settings. I write, direct, design, and occasionally even act. I’ve also taught acting methods.</p>\n<p>I’m currently a member of the Autism Theatre Network, through the <a href=\"http://www.appliedtheatrecenter.org/autismnetwork.html\" target=\"_blank\">Applied Theatre Center</a>. I’m involved with an agency that uses theatre to teach social pragamatics to children, adolescents, and young adults who are on the Autism spectrum.</p>\n<p>It’s a stage of a different sort.</p>\n",
"excerpt": "<p>I’ve always been wrapped up in the magic of the stage. When I was a junior in high school, I was cast in a chorus role of my first play. I froze as I was about to make my first entrance in front of an audience of several hundred people. The person behind me pushed [...]</p>\n",
"date": "2013-04-10 14:08:27",
"modified": "2013-04-16 17:34:18",
"categories": [],
"tags": [],
"author": {
"id": 1,
"slug": "truthscribe722gmail-com",
"name": "David Brown",
"first_name": "David",
"last_name": "Brown",
"nickname": "REDACTED",
"url": "",
"description": ""
},
"comments": [],
"attachments": [],
"comment_count": 0,
"comment_status": "open",
"custom_fields": {}
}
}
Upvotes: 3