0

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.

Jacob Pickens
  • 471
  • 1
  • 7
  • 15

3 Answers3

2

Are you sure you're loading jQuery correctly? Try jQuery.ajax you should be able to pass data through getJSON

http://api.jquery.com/jquery.getjson/

$.getJSON( "test.js", { name: "John", time: "2pm" } )
   .done(function( json ) {
   console.log( "JSON Data: " + json.users[ 3 ].name );
})
.fail(function( jqxhr, textStatus, error ) {
   var err = textStatus + ", " + error;
   console.log( "Request Failed: " + err );
});

Also you can do echo json_encode(['amount'=>$user]) instead of making the string yourself and get the same output.

Mike
  • 189
  • 1
  • 2
  • 18
1

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);
});
joyBlanks
  • 6,419
  • 1
  • 22
  • 47
  • It may have worked however I uploaded the new files to the webserver and now it wont load in the kik browser, it says this: `Console.ERROR: Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png (data:text/html,chromewebdata:12)` I don't know if you are familiar with android but I dont know exactly what could have triggered this – Jacob Pickens Aug 18 '15 at 18:55
1

If you want, you can pass your parameters through the url

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