简体   繁体   English

从表单HTTP GET响应中使用XML-仅前端

[英]Using XML from a form HTTP GET response - front end only

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. 我想构建一个简单的网页,该网页通过GET请求在不同的域上查询数据库,并在页面/新页面上指示查询是否成功。 Like a downforeveryoneorjustme for this specific database. 就像这个特定数据库的永久失败者一样。

I don't think I can make an AJAX GET request because of the different domain. 由于域不同,我认为我无法发出AJAX GET请求。

I can get a valid XML response with something like the following, but I have no idea how to use that response. 我可以通过类似以下内容获得有效的XML响应,但是我不知道如何使用该响应。 Is there a simple way using only javascript? 是否有一种仅使用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. 编辑:我还需要检查返回的XML的值之一。 Thanks. 谢谢。

Cross-domain AJAX requests aren't impossible AJAX cross domain call . 跨域AJAX请求不是不可能的AJAX跨域调用

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. 如果要查询另一个网站,查看查询是否成功的最简单方法是检查HTTP响应代码。 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. 您未指定服务器端语言,如果您不使用AJAX,我怀疑您将使用该语言处理请求,因此我无法提供任何详细信息,但是根据您收到响应的方式,您只需检查一下响应码等于200,表示请求成功完成。

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. 至于检查数据库是否关闭,根据本文的HTTP HTTP状态码已关闭,这种情况将返回500或503。

You can still use AJAX GET request though your in different domain as long as you have valid AJAX request. 只要您具有有效的AJAX请求,您仍可以在其他域中使用AJAX GET请求。 You can simply use jQuery ajax like this: 您可以像这样简单地使用jQuery ajax:

$.get('your_URL', function(response) {
  $('.result').html(response);
  alert('Load was performed.');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM