8

I am trying to return the JSON data from the specified URL but when the alert pops up it just shows [object Object] (I realize the object object is not in fact an error). I would like to spit out the position name and other fields in the alert. How do I do this?

Here is an example of the JSON I am looking at (the full file has about 30 postings)

[
  {
    "m_id": 473644,
    "m_positionName": "Application Monitoring Software Engineer",
    "m_positionLocations": [
      {}
    ],
    "m_active": true,
    "m_description": "Job Responsibilities:\r\n\r\n-Create world class application monitoring tools and dashboards for our health care applications\r\n\r\n-Develop business rules to pro actively identify and re-mediate system-level issues before they occur.\r\n\r\n-Create business intelligence reports for internal and external use as a supplement to software products.\r\n\r\n\r\n\r\nJob Requirements:\r\n\r\n-BS or MS Degree in computer science or any engineering discipline.\r\n-4+ years of experience with Java (or other object-oriented programming language).\r\n-Experience in SQL, Struts, Hibernate, Spring, Eclipse, JSP, JavaScript.\r\n-Highly motivated and self-driven personality.\r\n-Excellent interpersonal and leadership skills.\r\n-A vision for the future and a desire to make a difference.\r\n-Experience with Maven, Tomcat, PostgreSql, Jasper Reports,",
    "m_postedDate": "Jun 29, 2012 9:17:19 AM",
    "m_closingDate": "Jun 29, 2013 12:00:00 AM"
  }
]

And here is the script I am using.

 $.ajax({
 type: "GET",
 url: '/wp-content/themes/twentyeleven/js/jobopenings.json',
 async: false,
 beforeSend: function(x) {
  if(x && x.overrideMimeType) {
   x.overrideMimeType("application/j-son;charset=UTF-8");
  }
 },
dataType: "json",
success: function(data){
alert(data);
}
});

Any Help is much appreciated.

1
  • 9
    Use console.log instead of the alert. Commented Nov 19, 2012 at 15:15

3 Answers 3

20

You could always turn the object into a string and alert that.

alert(JSON.stringify(data));
Sign up to request clarification or add additional context in comments.

1 Comment

That does spit out the data in the object but I want to specifically spit out the m_description field into some html say an li
7

Try this:

success: function(data)
{
  var _len = data.length;
  , post, i;

  for (i = 0; i < _len; i++) {
    //debugger
    post = data[i];
    alert("m_positionName is "+ post. m_positionName);
  }
}

3 Comments

Now we're cooking. This spits out every position thank you!
Now if I wanted to append this data to the body rather than alert it what would I write. I came up with this but its not working. ('<li>' + "m_positionName is " + post.m_positionName + '</li>').appendTo('body');
@user1324700 success: function(data) { var _len = data.length; , $span = $('<span>') , post, i; for (i = 0; i < _len; i++) { //debugger post = data[i]; $span.html("m_positionName is "+ post. m_positionName).appendTo('body'); alert("m_positionName is "+ post. m_positionName); } }
1

When jQuery receive a json, jQuery automatically convert it to a javascript object. So data just contains your object ready to be used. If you want to access to the original text of the response, you can do this :

success: function(data, textStatus, jqXHR){
    alert(jqXHR.responseText);
}

1 Comment

This does spit out the raw text but I want to spit out m_positionName , m_description and others

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.