初学者的问题:这是我的服务器端代码,非常简单:
@GET
@Path("/query")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Map<Integer,String> getUsers(
@QueryParam("from") int from,
@QueryParam("to") int to) {
Map<Integer, String> orders = new HashMap<Integer,String>();
orders.put(1, "order1");
orders.put(2, "order2");
orders.put(3, "order3");
return orders;
}
这是我的 JQuery 代码:
$(document).ready(function() {
$('#id1').mouseover(function() {
alert("ok");
var formData = {from:3, to:2};
var result = $.ajax({
url: 'http://localhost:8080/MyJSON/resources/entities.customer/query',
type: "GET",
data: formData,
dataType: 'json',
success: function (data) {alert(data);}
});
});
}); // end ready
如何解析数据对象并获取json,即{"1":"order1","2":"order2","3":"order3"}