2013-03-07 4 views
0

매개 변수를 익명 함수로 전달하는 데 문제가 있습니다. Images는 파일 이름의 배열입니다. 나는 그것을 전달하려고 시도하기 전에 정의되어 있는지, 그리고 아래의 익명 함수에서는 정의되지 않았 음을 확신한다. 거래는 뭐니? 세부 사항에 대해 사과드립니다. 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); 
시도 그것은해야 var images = data.responseText.split(":");을 사용

이미지 배열을 더 높은 범위에서 setTimeout으로 전달할 필요가없고 setTimeout 콜백 내에서 액세스 할 수 있습니다.

+0

편집 해 주시면 고맙겠습니다. 다른 코드에서 문제가 발생했습니다. 했다. – TheMonarch

0

를 사용하여 당신은

// Receives a string with a comma separated list of filenames (images)을 썼다 그러나 당신은 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

관련 문제