Solved

example of jquery to render json data on browser

Posted on 2013-05-28
8
426 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 55

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 55

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 55

Expert Comment

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

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to dynamically set the form action using jQuery.

828 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