Solved

example of jquery to render json data on browser

Posted on 2013-05-28
8
421 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 51

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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

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 51

Expert Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now