Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

$.getjson Not Retrieving Data

JSON jquery json

  • Please log in to reply
1 reply to this topic

#1 Collossus

Collossus

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 18 April 2012 - 08:56 AM

I am having problems getting getJSON call to work. At the moment it doesn't retrieve any data, however when I change the '$.getJSON' to ' $.get' it retrieves the data in it's encoded format:


[{"Page":"User Journey","Description":"Interactive User Journey Diagram","Bounce_Rate":"0","Avg_Time_On_Page":"0","Page_Views":"0","Click_Rate":"0"}


What am I missing from the $.getJSON call?

getstatistics.php:

Copy code

$query="SELECT Page, URL, Description, Bounce_Rate, Avg_Time_On_Page, Page_Views,
$result=mysql_query($query);
mysql_close();
?>
<?php
$array = array();
while ( $row = mysql_fetch_assoc( $result ) ) {
$array[] = $row;
}
echo json_encode($array);

JQuery:
$.getJSON('getstatistics.php', function(data) {
$.each(data, function(index, value) {
$('#paragraphtochange').eq( index).text( value);
})
});
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 18 April 2012 - 10:44 AM

I haven't worked with jQuery a lot, but have you compared your results with the documentation?

http://api.jquery.com/jQuery.getJSON/
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: JSON, jquery, json

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download