i want to make a small code that just send a POST request to a server and print "hi" if the server answer. I have this ajax function that realize a post request to vert.x server:
$.ajax({
type: 'POST',
url: 'http://localhost:9999',
data: {message:tmpMessage},
async:false
}).done(function() {alert("succes");})
.fail(function() { alert("fail");})
.always(function() { alert("complete");});
And this java code which is a vert.x server that just gives a response back when he recieve POST request.
httpServer.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest request) {
System.out.println("incoming request!");
if(request.method() == HttpMethod.POST){
HttpServerResponse response = request.response();
response
.end();
}
}
});
But it never goes in the callBack function .done(function() {aler("success");} and i don't understand why. I think that it's not the way to use the HttpServerResponse but i can't find a proper answer anywhere. Can someone help ?
I'm not sure what's the type for your POST
, but even in that way you are comparing it looks a little bit suspicious .
Anyway, assuming you are using Vert.x 2.x, change your code section for this:
if ("POST".equals(request.method())) {
request.response().end();
}
...and you are good to go.
NOTE: You can find a type to compare POST
in any other library/framework, like those constants or enums.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.