2013-03-07 101 views
0

我無法將參數傳遞給匿名函數。圖像是一組文件名。我確信它是在我試圖傳遞它之前定義的,並且它在下面的匿名函數中是未定義的。這是怎麼回事?我對任何細節的缺乏表示歉意。使用jQuery 1.9將參數傳遞給匿名函數undefined jquery

function setup_slideshow(){ 
$('#slide1').fadeOut(0); 
$('#slide0').fadeIn(0); 
$.ajax({ 
    url: "/inc/phplib/fetch_images.php", 
    async: true, 

    // Receives a string with a colon separated list of filenames (images) 
    complete: function(data){ 
     var images = data.responseText.split(":"); 
     $('#slide0').attr("src", images[0]); 
     $('#slide1').attr("src", images[1]); 
     var t = setTimeout(function(images){ 
      move_slideshow(images, 2, 1); 
     }, 550); 
    } 
}); 
} 

回答

0

嘗試

var images = data.responseText.split(":"); 
    $('#slide0').attr("src", images[0]); 
    $('#slide1').attr("src", images[1]); 
    var t = setTimeout(function(){ 
     move_slideshow(images, 2, 1); 
    }, 550); 

你不需要的圖像陣列的setTimeout通過其在較高的範圍,是setTimeout的回調

+0

我欣賞的幫助,這是造成其他代碼我的問題也有。 – TheMonarch 2013-03-07 23:48:43

0

你寫// Receives a string with a comma separated list of filenames (images)

但是你用var images = data.responseText.split(":");應該var images = data.responseText.split(",");

的完整代碼

function setup_slideshow(){ 
    $('#slide1').fadeOut(0); 
    $('#slide0').fadeIn(0); 
    $.ajax({ 
    url: "/inc/phplib/fetch_images.php", 
    async: true, 

    // Receives a string with a comma separated list of filenames (images) 
    success: function(data){ 
     alert(data); //to check what you get in data 
     var images = data.split(":"); 
     $('#slide0').attr("src", images[0]); 
     $('#slide1').attr("src", images[1]); 
     var t = setTimeout(function(images){ 
      move_slideshow(images, 2, 1); 
     }, 550); 
    } 
    }); 
} 
+0

對不起,冒號分隔的列表內訪問,將編輯 – TheMonarch 2013-03-07 06:19:30

相關問題