您可以使用AJAX或基本的发布方法。
只需创建一个AJAX(或基本的POST调用),即可将请求发送到包含Servlet(是否为localhost)的服务器。
您可以在那里构造一个JSON对象,并将其作为响应的一部分返回。
然后,您可以使用基本的for循环解析JSON对象,并根据需要使用数据。
示例(使用jQuery库):
$.ajax(
{
type : 'post',
url : 'folder/ServletName',
dataType: 'json',
contentType: 'text/plain',
async: false,
data :
{
'request' : true
},
success : function(data)
{
var id = '';
for(var i = 0; i < data.length; i++)
{
id = data[i].id;
// Use id or other variables that you know of
}
},
complete : function(data)
{
}
});
coffeecsript的类似方法(略有不同)
$.ajax
type: "POST",
url : "folder/ServletName#
data : JSON.stringify({"request" : true})
dataType: "json"
contentType: "text/plain"
async: false
error: (jqXHR, textStatus, errorThrown) ->
$('#div').append "AJAX Error: #{textStatus}"
success: (data, textStatus, jqXHR) ->
for foo in data
id= foo.id
$("#div").html(id)
希望对您有所帮助,我要入睡了,明天再检查。