Is it possible to pass predefined variables to functions called upon successful jQuery $.get request?
As in the example below the PHP script would return "bar":
var extra = "foo";
$.get(baar.php, function(data, extra){
alert(extra + data);
});
Thus my goal being an alert box proclaiming "foobar" to the world.
Thanks.
You don't need to pass it, extra
will be available inside the callback because of how JavaScript scoping works. So:
var extra = "foo";
$.get('baar.php', function(data){
alert(extra + data);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With