Is there a request method in Javascript that allows me to send message m
and data v
to the server without having to deal with the response? If not, what is the best way to return a minimally acceptable string back to the client, which will not be processed?
I attempted to achieve this using the following Javascript code:
function report(m,v){
io=new XMLHttpRequest();
io.open("POST","http://localhost:3000?m="+m,true);
io.send(JSON.stringify(v));
return false;
};
When I responded with what I believed to be a minimal serialized string generated by Ruby like
[].to_json
The client Javascript displayed an error saying
the server responded with a status of 500 (Internal State Error)
.
Edit
On the server side, my Ruby code looks something like this:
Rack::Handler::Thin.run(Rack::Builder.new do
map("/") do
run(->env{[200, {}, [server.ajax(
Rack::Utils.parse_nested_query(env["QUERY_STRING"]),
env["rack.input"].read
)]]})
end
end, Port: 3000)
where the server.ajax
method is defined as follows:
def ajax h, v
m, v = h["m"].to_sym, JSON.parse(v)
case m
...
when :error
puts m
p v
return "" # or `[].to_json` or whatever
...
end
end
In this particular instance, the message m
being passed is 'error'
. After analyzing the output from the above code snippet, it seems like the issue lies with the response handling.