Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

example of jquery to render json data on browser

Posted on 2013-05-28
8
Medium Priority
?
433 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 59

Accepted Solution

by:
Julian Hansen earned 2000 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
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 
LVL 59

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 59

Expert Comment

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

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

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.
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

715 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