javascript 以 xml 作为请求数据的 html POST 请求示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21753211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:36:59  来源:igfitidea点击:

Example on POST request in html having xml as request data

javascripthtmlweb-servicesxmlhttprequest

提问by Yatin

<!DOCTYPE html>

<html>

<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">

</script>

<script>

$(document).ready(function(){

? $("button").click(function(){

? ? $.post("url",

? ? '<MESSAGE><HEADER><LOGIN>005693</LOGIN></HEADER><SESSION><LATITUDE>0.0</LATITUDE><LONGITUDE>0.0</LONGITUDE><APP>SRO</APP><ORG>MNM</ORG><TRANSACTION>PRELOGIN</TRANSACTION><KEY>PRELOGIN/ID</KEY><TYPE>PRELOGIN</TYPE></SESSION><PAYLOAD><PRELOGIN><ID>005693</ID><USERNAME>005693</USERNAME><PASSWORD>tech@2014</PASSWORD></PRELOGIN></PAYLOAD></MESSAGE>',

? ? function(data,status){

? ? ? alert("Data: " + data + "\nStatus: " + status);

? ? });

? });

});

</script>

</head>

<body>


<button>Send an HTTP POST request to a page and get the result back</button>


</body>

</html>

Have tried the same but gives origin null is not allowed by access control allow origin HI I Have a web request to send with xml request body as post request to a url in html How can I achieve this . I got JBOSS server at another end or any other server as to say

已经尝试过相同的方法,但是访问控制不允许提供原点 null 允许原点 HI 我有一个 web 请求要发送 xml 请求正文作为对 html 中的 url 的 post 请求我如何实现这一点。我在另一端或任何其他服务器上有 JBOSS 服务器,如说

<MESSAGE>
  <HEADER>
    <LOGIN>1111</LOGIN>
  </HEADER>
  <SESSION>
    <LATITUDE>0.0</LATITUDE>
    <LONGITUDE>0.0</LONGITUDE>
    <APP>SRO</APP>
    <ORG>MNM</ORG>
    <TRANSACTION>PRELOGIN</TRANSACTION>
    <KEY>PRELOGIN/ID</KEY>
    <TYPE>PRELOGIN</TYPE>
  </SESSION>
  <PAYLOAD>
    <PRELOGIN>
      <ID>1111</ID>
      <USERNAME>1111</USERNAME>
      <PASSWORD>passsss</PASSWORD>
    </PRELOGIN>
  </PAYLOAD>
</MESSAGE>

I have tried everything but I get a status as 0 but readystate as 1 and then 4

我已经尝试了所有方法,但我的状态为 0,但就绪状态为 1,然后为 4

I tried the same thing with the below code

我用下面的代码尝试了同样的事情

回答by Quentin

The only things that differ from doing a regular POST request with XMLHttpRequest when you are sending XML are that you must:

与在发送 XML 时使用 XMLHttpRequest 执行常规 POST 请求不同的是,您必须:

I have tried everything but I get a status as 0 but readystate as 1 and then 4

我已经尝试了所有方法,但我的状态为 0,但就绪状态为 1,然后为 4

It sounds like you are making a cross-origin request and you don't have permission. Look at your browser's error console. It is probably complaining about that. See this questionif that is the case.

听起来您正在发出跨域请求,但您没有权限。查看浏览器的错误控制台。它可能是在抱怨那个。如果是这种情况,请参阅此问题