});作者: shiwudao 時間: 2013-08-21 22:20
ok, I got the reason. AJAX should only access the URL in the same domain. I put the AJAX code in a local HTML, hence can't access the server.
updated server code as below, and put the AJAX html under "/", the access point it "http://localhost:9000/ajax.html"
require 'webrick'
$mydata="<root><data>test1</data><data>test2</data></root>"
class MyServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
response.status = 200
response.content_type = "text/xml"
response.body = $mydata
end
end