求一个AJAX+SOAP小小代码 能用就结贴100分

一头头 2013-03-04 11:37:02
我主要是做java的 所以web这一块不熟悉哇。所以来问问

需要实现一个小功能

1. 需要有一个button,按这个button就发送一个SOAP代码到我的server。SOAP XML 我自己有的。
2. 再有一个textbox把 SOAP返回的XML显示在这个textbox里面。

我实现了REQUEST部分但是response部分做不来。不过也可以用ajax写。

先行谢过哇


<html>
<head>
<title>SOAP Connection</title>
<script type="text/javascript">
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'https://xxxx.com:443/ws/xxxx', true);

// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soapenv:Envelope ' +
'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ' +
xxxxx +
'</soapenv:Body>' +
'</soapenv:Envelope>';

xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {

alert('done use firebug to see responce');
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...CC
}
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Soap" onclick="soap();" />
</div>
</form>
</body>
<html>

...全文
193 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
一头头 2013-03-06
  • 打赏
  • 举报
回复
webservice改不了 您能实现这个吗 好像很简单的哇 就是我不会
Go 旅城通票 2013-03-06
  • 打赏
  • 举报
回复
确认你的soap信封构建对了没有? 构建对了你的代码应该没什么大问题了,除了firefox下的端口跨域,这个只能统一端口号,创建xhr对象要注意判断是否支持XMLHttpRequest。。如果IE禁用XMLHttpRequest就只能用acx
var xmlhttp =window.XMLHttpRequest? new XMLHttpRequest():new ActiveXObject("microsoft.xmlhttp");
你如何测试的?不要双击通过file浏览,要不也会出现跨域错误,要通过搭建服务器用http访问
Go 旅城通票 2013-03-05
  • 打赏
  • 举报
回复
将你的webservice配置为可以get/post访问就不用构造soap信封了,太麻烦。。 还需要注意的不要跨域,并且firefox下网站的端口和ajax请求的网站的端口要一致,要不firefox端口不一致也算跨域报错

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧