2012-05-17 117 views
0

我在这里搜索了一个解决方案,但他们似乎只是导致了其他错误我太缺乏经验了(第一个版本是在PHP中,现在我必须将它移动到存储程序)。我拥有的是我校园的地图,当用户点击建筑物时,会弹出一个信息泡泡以显示一些信息和图片库。图片的地址存储在一个表格中,所以我需要它们返回到一个数组中,以便我可以遍历它们。拿到名单的电话是:在程序之间传递数组

$.ajax({ //get the picture URLs, load into array 
     type: "post", 
     url: "video_tour.get_pics", 
     data: { pBldg_id: building 
     }, 
     error: function(xhr,thrownError) { alert("error get pics"); }, 
     success: function(data){ 
        $.each(data, function(index,obj) { 
         picArray[index] = obj.ADDRESS; 
        }); 
     } 
});//and ajax for pic load 

和被调用过程:

procedure get_pics(pBldg_id int) is 
    type array_varchar is table of varchar2(2000) index by binary_integer; 

    array_of_pics array_varchar; 
    v_counter int := 0; 
begin 

for i in(select address from ucs.campus_pictures where building_id = pBldg_id and thumbnail = 1) loop 
    array_of_pics(v_counter) := i.address; 
    v_counter := v_counter + 1; 
end loop;    

end get_pics; 

我如何可以报考array_of_pics回Ajax调用?

+0

您可能需要更改您的get_pics过程,因为过程不返回值。你可能想要一个功能。 – eaolson

回答

0

所以它并不像看起来那样复杂,我只需要打印的数据,因为它出来,并添加分隔字符:

for i in(select address from ucs.campus_pictures where building_id = pBldg_id and thumbnail = 1) loop 
htp.prn(i.address || ';'); 
end loop; 

,并在Ajax调用数组:

$.ajax({ //get the picture URLs, load into array 
        type: "post", 
        url: "video_tour.get_pics", 
        data: { pBldg_id: building 
        }, 
        error: function(xhr,thrownError) { alert("error get pics"); }, 
        success: function(data){ 
         $.each(data.split(";"), function(index,obj) { 
            picArray[index] = obj; 
           }); 

        } 
      }); 

感谢球员抽空帮忙!

0

我假设你有一些处理请求的中间件(即使它是一个PHP页面)然后调用该过程。从那里开始,你实际上想返回一个游标(见下面的例子)。在你的中间件中,你将循环来自光标的结果集。

create or replace function get_pics(bldg_id_in ucs.campus_pictures.building_id%TYPE) 
return sys_refcursor 
as 
ref_cursor sys_refcursor; 
begin 
    open ref_cursor for 
    select address from ucs.campus_pictures where building_id = bldg_id_in and thumbnail = 1; 
    return ref_cursor; 
end; 
+0

这里没有任何底层的PHP代码。存储过程将html/javascript打印到浏览器。我几乎不熟悉游标,我明天会去检查一下 - 因为它是jQuery调用过程,是我想要返回的游标吗?或者我想不打印光标的结果?如何设置(我不知道是否清楚,是使用存储过程来编写html正常?)被称为过程打印调用过程需要返回值的任何数据。所以我认为我需要它以一种可以转换成JS数组的形式回来。 – ini

+0

你写道,存储过程打印HTML/JavaScript的borwser。它是否使用HTP包完成? –

+0

是的,我们使用htp.prn。 – ini