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.
我正在使用ajax对我编写的java程序(实现com.sun.net.httpserver.httphandler)发帖。我有一个问题,我可以执行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. 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.
jQuery代码中的错误处理程序有一个对象,其中包含“错误”。另外一个细节,我的服务器在端口80上,据我所知,没有跨域查询...我想。
Any suggestions are appreciated,
任何建议表示赞赏,
mj
MJ
1 个解决方案
#1
0
I figured it out.
我想到了。
I was making a cross domain ajax call. I just changed the content-type to jsonp and it worked.
我正在进行跨域ajax调用。我刚刚将内容类型更改为jsonp并且它有效。
#1
0
I figured it out.
我想到了。
I was making a cross domain ajax call. I just changed the content-type to jsonp and it worked.
我正在进行跨域ajax调用。我刚刚将内容类型更改为jsonp并且它有效。