我们可以像这样进行ajax调用http://localhost:8080/_rest_/hello
吗?
如果我进行此 ajax 调用,我将得到响应null
而不是页面内容。但是如果我在浏览器中运行或执行命令
curl http://localhost:8080/_rest_/hello
它工作正常。请帮助我,谢谢。
我们可以像这样进行ajax调用http://localhost:8080/_rest_/hello
吗?
如果我进行此 ajax 调用,我将得到响应null
而不是页面内容。但是如果我在浏览器中运行或执行命令
curl http://localhost:8080/_rest_/hello
它工作正常。请帮助我,谢谢。
经过一些调查,这就是我发现的:
$.ajax({ url: "http://localhost:8080/_rest_/hello", type: "POST", datatype: "html", success: function(resp) { alert(resp); } });
有效(注意警报而不是 html 调用)。所以服务器会给你一个响应(正如你所说,curl成功)。
您的服务器响应的内容是什么?
我认为您应该为 / rest /hello返回一个 Resource.raw_text(" <some/><html/>
") 响应,因为 jQuery html 函数似乎只采用有效的 HTML。
否则,您可以这样做:
$('#response').load('http://localhost:8080/_rest/hello');