tags:

views:

27

answers:

2

I cant figure out why the this alert() part below is not working when I call it from $.getJSON???

function parseInfo(data)
    {
       alert("getJSON worked");
    }

Firebug says I connecting to the server with a 200 OK code

<!DOCTYPE html>
 <html lang="en">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
   <script type="text/javascript">
       $(document).ready(function(){
                 $.getJSON('getData.php', {'data_id' : 'mysql_data'}, parseInfo);
                 });


function parseInfo(data)
{
    alert("getJSON worked");
}

   </script>
</head>
<body>


<form action="getData.php" method="get">
Name: <input type="text" name="fname" />
<input type="submit" />
</form> 


</body>
A: 

Couple of things to try.

  1. Try updating your jQuery to 1.4.2.
  2. Change your data code to: { data_id : 'mysql_data'}
  3. Inspect the request/response using firebug. This is invaluable in determining what exactly is being sent & received
Alastair Pitts
A: 

Doc here.

PART 1

I think it is best to put the callback directly inside of the getJSON() method.

$(document).ready(function(){
        // DATA IS LOADED FIRST AND PARSED TO GET READY TO ME MAPPED AND PUT INTO SORTABLE TABLES
        $.getJSON("getData.php",
            function(json){
                alert( "Got JSON Data  ");
                //DO STUFF HERE
                    }
                    }

PART 2

I simplified the .php file

getData.php can simply look like this:

$all_tdys = array();
echo json_encode($all_tdys);

PART 3

as @mway warned I made sure to pass an array and not a MySQL object.

indiehacker