Search code examples
javascriptjqueryjsonzeptoappjs

Can't pass parameters to $.getJSON()


I'm using jQuery and PHP to communicate with my MySQL database. jQuery calls a PHP script and passes along the parameters to look up, then PHP looks through my MySQL database, turns it into JSON and then echos the JSON back to my jQuery. In theory that should work. It returns the jQuery in the correct format and all, however I run into a problem when I use the optional data parameter in $.getJSON(). Heres what I'm doing:

// I would like to send a string to the php file on my webserver
$.getJSON('http://garbagewire.tk/server/refresh.php', { user:"jacob.pickens" }, function(data) {
    console.log(data.ammount);
});

However, I never get the data logged back, I get this error here:

08-18 13:35:01.866  17420-17420/? W/WebConsole﹕ Console.ERROR: Uncaught TypeError: Object #<Object> has no method 'call' (http://garbagewire.tk/zepto.js:2)

And here's my php: (MySQL stuff omitted)

<?php 

$user = $_GET['user'];

echo "{";
echo "\"ammount\":", json_encode($user);
echo "}";
?>

I'm using the App.js api to make a kik webpage if that is to any importance.


Solution

  • Try this, I guess you got confused with $.post syntax

    $.getJSON('http://garbagewire.tk/server/refresh.php?user=jacob.pickens', function(data) {
        console.log(data.ammount);
    });