confiq
confiq

Reputation: 2918

best way to detect server information in javascript

I'm trying to detect server information using only JS such as HTTP response code & content.

Because of Same-origin policy I'm not allowed to use normal ajax request and therefore i'm forced to following workarounds

  1. Using JSONP is great but in case of error I can't know what HTTP code or content of response page

  2. Using Image request is not really option cause, same as above, I can't know HTTP code or content. I can only know if I loaded image to DOM.

  3. Using AJAX with CORS. This is best solution so far but in case it is not my server I can't detect HTTP code :(. Same applies for flash and crossdomain.xml policy.

  4. Using iframe, as i know I can't detect HTTP code or content.

While writing this I've just notice that I'm dealing with XSS issues here but all I need from JS is HTTP code OR content of another domain.

All suggestions are welcome.

Upvotes: 0

Views: 107

Answers (1)

plalx
plalx

Reputation: 43718

I fear that is not possible using client-side JavaScript, unless the server implements a mechanism allowing you to gather this information by either simply supporting CORS or include the information in the JSON response of the JSONP request.

However, if you have some server-side support you could put in place an API that allows you to do so. E.g. You call a service on your server which in turn performs the request on the remote server and returns the desired information.

Upvotes: 1

Related Questions