【发布时间】:2014-08-24 00:18:29
【问题描述】:
我有一个通过 ajax 与我的肥皂网络服务通信的移动应用程序。
用户必须插入 2 个字段才能登录(uname 和密码),当他按下登录时 按钮,调用 javascript 方法通过 ajax 将数据发布到 Web 服务。 我可以从 html 页面获取输入值,但是当我调试 Web 服务时,我看到收到的参数是 null 而不是用户输入的值,我不明白为什么..
function login()
{
var uname = document.getElementById('uname').value;
var pass = document.getElementById('password').value;
var soapRequest =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\
xmlns:xsd="http://www.w3.org/2001/XMLSchema"\
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\
<soap:Body>\
<Login xmlns="http://service.webservice.org/">\
<Name>' + uname + '</Name>\
<Password>' + pass + '</Password>\
</Login>\
</soap:Body>\
</soap:Envelope>';
$.ajax({
type : "POST",
url : "http://localhost:8080/WebService/Service",
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success : function(data, status, req, xml, xmlHttpRequest, responseXML)
{
var xmlText = $(req.responseXML).find('LoginResult').text();
alert(xmlText);
},
error: function ()
{
alert("error");
}
});
【问题讨论】:
-
> 我可以从 html 页面获取输入值 显然不行。确认页面上确实存在具有这些 id 的元素(
uname和password)。 -
它们在 html 页面上找到,我使用 "" 将 js 函数链接到 html 页面,因此我可以获得输入值.. 即使我在登录方法的前 2 行之后使用“alert”方法,我也可以看到输入值
-
即使我传递的是硬编码字符串而不是 'uname' 和 'pass' 参数,我也会得到 null
-
啊,我明白了。您在服务器上得到 null,而不是在客户端上。这更像是一个“如何用 JavaScript 做肥皂”的问题。
-
是的,这就是问题所在.. 我不知道为什么.. 肥皂请求很好
标签: javascript jquery ajax web-services soap