/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] JavaScript – asynchronous request to a servlet

Hi all,

I try to asynchronously pass a request to a servlet using the XMLHttpRequestObject.

When I use method GET in open(), the request seems to be sent, but the servlet receives an empty(null) request and it returns a default response (not the required one).

When I use method POST, I also try to set the request header using:
XMLHttpRequestObject.setRequestHeader(‘Content-Type’,’application/x-www-form-urlencoded’);
However, in this case the XMLHttpRequestObject.status = 405. Hence, I’m afraid the request header is not set properly – maybe I set it the wrong way.

When I try to display the response headers using: document.write(“Get All Response Headers: ” + XMLHttpRequestObject.getAllResponseHeaders);
…the output is:

Get All Response Headers: function getAllResponseHeaders() { [native code] }

If I try to display the changes in the XMLHttpRequestObject status, I get the following output:

OPENED state (1)
HEADERS RECEIVED state (2)
LOADING state (3)
DONE state (4)
state: 1
HEADERS RECEIVED state (2)
LOADING state (3)
DONE state (4)
state: 2
LOADING state (3)
DONE state (4)
state: 3
LOADING state (3)
DONE state (4)
state: 3
LOADING state (3)
DONE state (4)
state: 3
LOADING state (3)
DONE state (4)
state: 3
LOADING state (3)
DONE state (4)
state: 3
LOADING state (3)
DONE state (4)
state: 3
DONE state (4)
state: 4

I read the XMLHttpRequestObject documentation: [url]http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest[/url], but I still cannot figure out what the problem is.

I’ll be happy if you could give me any hint about what could be wrong or how I can continue debugging. I already ran out of ideas.

Thanks,
Pesho

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Pesho318i spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...