Solved

example of jquery to render json data on browser

Posted on 2013-05-28
8
424 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
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39203448
0
 
LVL 7

Expert Comment

by:gudii9
ID: 39203456
0
 
LVL 52

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
3 Use Cases for Connected Systems

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

 
LVL 52

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 52

Expert Comment

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

Featured Post

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now