我正在ajax
打我的服务器,需要从中获取值。怎么做?
这是ajax
:
$.ajax({
type: "POST",
url: "http://localhost:8080/myapp/etc",
contentType: "application/json; charset=utf-8",
data: {"id": "1", "somekey": "somevalue"},
dataType: "json",
async: "true",
success: function(msg) {
alert("success " + msg);
},
error: function(msg) {
alert("error " + msg.toString());
}
});
我正在使用,Restlets
所以我假设值将在Representation实体中。这是方法:
@Post
public Representation doPost(Representation entity) {
String et = java.net.URLDecoder.decode(entity.getText(), "UTF-8");
System.out.println("the entity text " + et);
}
打印出来"id": "1", "somekey": "somevalue"
。但是,如何获得其他值?的async
,在url
等?
Restlet将使您能够访问请求内发送的元素(URL,标头,有效负载),但不能访问用于构建请求的客户端配置属性。
您可以使用Chome控制台或Firebug之类的工具查看AJAX调用请求中发送的内容。
该属性async
未在请求内发送,因此您无法从服务器端获取。对于URL,可以在服务器资源中使用以下代码:
Reference reference = getRequest().getResourceRef();
String url = reference.toString();
有关更多详细信息,请参见该类的javadocs Reference
:http : //restlet.com/technical-resources/restlet-framework/javadocs/2.1/jee/api/org/restlet/data/Reference.html。此类允许您访问其中的每个元素(主机域,端口,路径等)。
希望对您有帮助,蒂埃里
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句