简体   繁体   English

java httpexchange 响应 jquery ajax 调用为空

[英]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).我正在使用 ajax 发布到我编写的 java 程序(实现 com.sun.net.http.server.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.我有一个问题,我可以调用 ajax 并看到它被 java 程序捕获,但是在 Firebug 中,响应是空的。

Here is my ajax code.这是我的 ajax 代码。

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.getResponseBody();
    os.write(response.toString().getBytes());
    os.close();

The error handler in the jQuery code has an object that says "error" in it. jQuery 代码中的错误处理程序有一个 object,其中显示“错误”。 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.另外一个细节,据我所知,我的服务器位于端口 80 上,没有进行跨域查询......我想。

Any suggestions are appreciated,任何建议表示赞赏,

mj

I figured it out.我想到了。

I was making a cross domain ajax call.我正在进行跨域 ajax 调用。 I just changed the content-type to jsonp and it worked.我只是将内容类型更改为 jsonp 并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM