0

I want to build a simple web page that queries a database, on a different domain, via a GET request and indicate on the page/a new page if the query is successful. Like a downforeveryoneorjustme for this specific database.

I don't think I can make an AJAX GET request because of the different domain.

I can get a valid XML response with something like the following, but I have no idea how to use that response. Is there a simple way using only javascript? If not what do I need to look at to do this?

<form method="get" action="http://XXX.XX.XX.XX:XXX">
<input type="text" name="text" value="apples" />
<input type="text" name="number" value="4351" />
<input type="submit" value="go" >
</form>

EDIT: I also need to check one of the values of the XML returned. Thanks.

Community
  • 1
  • 1
K Groll
  • 518
  • 2
  • 8
  • 18

2 Answers2

1

Cross-domain AJAX requests aren't impossible AJAX cross domain call.

But anyways, your question is about how to parse the response. If you are querying another website the easiest way to see if the query is successful is to check the HTTP response code. You didn't specify a server-side language which I suspect you will be processing your request with if you aren't using AJAX, so I can't give you any specifics, but depending on how you receive the response you simply check that the response code equals 200, which indicates that the request completed successfully.

As for checking if a database is down, according to this article HTTP Status Code for database is down such a case would return a 500 or 503.

Community
  • 1
  • 1
Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
  • Sorry, I should have said I need to check a value in the returned XML too. Updated the question – K Groll Nov 26 '12 at 08:46
  • What language are you using to try and parse this stuff? – Levi Botelho Nov 26 '12 at 08:59
  • I'm really unfamiliar with anything after the form gets submitted. What do you suggest? – K Groll Nov 26 '12 at 23:15
  • 1
    I suppose what you could do is use an iframe to navigate to the page in question. You could then use JavaScript to pull the response from the iframe and then get the value of an element by using document.getElementById('elementid').value – Levi Botelho Nov 27 '12 at 06:48
0

You can still use AJAX GET request though your in different domain as long as you have valid AJAX request. You can simply use jQuery ajax like this:

$.get('your_URL', function(response) {
  $('.result').html(response);
  alert('Load was performed.');
});
SubRed
  • 3,169
  • 1
  • 18
  • 17