I have a problem passing a variable through into a jquery function:
function showImage(type, top, url) {
$.getJSON('<?php echo $_SERVER['PHP_SELF']?>',{
type: type,
top: top,
img: url,
action: 'imginfo'
}, function(retval) {
if (retval['isimg']) {
$('#tdDimensions').html(retval['dimension']);
$('#thPreview').html(retval['previewtext']);
alert($('#tdPreview').html());
alert(img);
This is part of my code, but the problem is that in the success function (function(retval)) I cannot acces the parameters passed to showImage() anymore.
How can I realise this so that the alert(img) in this code will work?
Just use
urlarg fromshowImage– your callback, as inner function, has access to it. Read more about closures if you’re not sure why.