开发者

java httpexchange response to jquery ajax call is empty

I'm using ajax to do a post to a java program I've written (that implements com.sun.net.httpserver.httphandler). I've got a problem that I can do the ajax call and see it get caught in the java program, however in Firebug, the response is empty.

Here is my ajax code.

jQuery.ajax({
    type: "POST",
    url: "http://localhost/applications/nvn",
    data: "command=GetNVN",
    dataType:"text",
    success: function(msg){
    var fdsa;
    fdsa++;
    init(msg);
    },
    error: function( foo ){
    var fff;
    fff++;
    }
});

And here is my server code.

    Headers headers = t.getRequestHeaders();
    Set<Map.Entry<String, List<String>>> entries = headers.entrySet();

    StringBuffer response = new StringBuffer();
    for (Map.Entry<String, List<String>> entry : entries)
      response.append(entry.toString() + "\n");

    t.sendResponseHeaders(200, response.length());
    OutputStream os = t.ge开发者_如何学GotResponseBody();
    os.write(response.toString().getBytes());
    os.close();

The error handler in the jQuery code has an object that says "error" in it. One additional detail, my server is on port 80 so as far as I know, there is no cross domain querying going on... I think.

Any suggestions are appreciated,

mj


I figured it out.

I was making a cross domain ajax call. I just changed the content-type to jsonp and it worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜