With jquery, I’m trying to make it so when the user clicks on a button it runs some code on another page and returns a number, which is placed into #result.
This is probably wrong, but am I on the right lines?
$("#button").click(function(){
$.post("getdata.php?get=a", function(data){
$('#result').html(data);
});
You’re very close
http://api.jquery.com/jQuery.post/
Your data is what you send to the server, in other words, get rid of the
?get=aand instead you’d put it like thisYou see, first you put your url, then you put what you’re sending to the server, then you put the callback function. For clearer code, sometimes it’s written like this
EDIT: for your purposes, here it is on JSfiddle http://jsfiddle.net/U5XHt/ note that the url doesn’t exist though.