用getJSON将php数组传递给jquery

updated: i use this:

$.getimagesarr = function(operation) {
  return $.ajax({
      type: 'POST',
      url: 'operations.php',
      data: {'operation':operation},
      async: false
    }).responseText
}


var jsonstring = $.getimagesarr('getimg');
var data = (new Function("return " + jsonstring))() 
if (data){
   ....
}

old: i want to pass a php aray to jQuery:

$.getimagesarr = function() {
    $.getJSON('operations.php', {'operation':'getimglist'}, function(data){
        var arr = new Array();
        arr = data;
        return arr;
    });  
}

var data = $.getimagesarr();
if (data){
 jQuery.each(data, function(i, val) {
     ....
    });
}

it return undefined

in php i have this:

function getimglist(){
    $results = $_SESSION['files'];
    echo json_encode($results);
}

it is possible?

The return arr; line isn't going to return a value for the $.getimagesarr function. It's going to execute asynchronously, after the $.getJSON() call has finished. You should move the bottom area of code to within the success event handler for the $.getJSON() call:

$.getimagesarr = function() {
    $.getJSON('operations.php', {'operation':'getimglist'}, function(data){
        if (data){
            jQuery.each(data, function(i, val) {
                ....
            });
        }
    });  
};