Solved

example of jquery to render json data on browser

Posted on 2013-05-28
8
427 Views
Last Modified: 2013-08-16
can you please give an example of jquery/ajax to fetch server data and render json data on browser
0
Comment
Question by:jgdvishnu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39203448
0
 
LVL 7

Expert Comment

by:gudii9
ID: 39203456
0
 
LVL 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39203735
// setup your vars to where you want to go
var url = 'http://someurl.com';

// and maybe some parameters of what you want to get
var data = {
   id: $('#somefield').attr('id');
};

// Post to the server as with a dataType of JSON
// Assuming server returns a JSON structure
// status : ok | fail
// error : if status = fail then this will be set to error message
// items : array of items 
//     text
//     add other variables here if you need them

$.post(url, data, function(response) { 
   // response ok so create list
   if (response.status == 'ok') {
     // in this case return is a list of items for a <ul> - so loop through 
     // and display them.
     for(i =0; i<response.items.length;i++) {
      $('ul').append($('<li/>').html(response.items[i].text));
     }
   }
   else {
     $('#error').html(response.error);
   }
 }, 'json');

Open in new window

Full code attached
working sample here http://www.marcorpsa.com/ee/t241.html
t241.html
t241.php
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39398178
@jgdvishnu

Please explain the C grade.

Have you read the grading guidelines?

A C grade for the answer here was really insulting.

Please read this article for information on how questions should be graded

http://support.experts-exchange.com/customer/portal/articles/481419
0
 

Author Comment

by:jgdvishnu
ID: 39415075
want to change it to Grade A
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39415199
@jgdvishnu - it has been - thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question