[英]Javascript Ajax is returns undefined when calling a Web Service
I am using JavaScript rather than JQuery to call a web service. 我正在使用JavaScript而不是JQuery来调用Web服务。 But the problem is I keep getting undefined back as a result.
但是问题是,结果一直让我变得不确定。 I have done some searching for this but all I seem to find is JQuery related post instead of JavaScript related.
我已经为此进行了一些搜索,但是我似乎只找到了JQuery相关的文章,而不是JavaScript相关的文章。
I know that the webservice itself gets the right inputs and returns the right output. 我知道Web服务本身会获得正确的输入并返回正确的输出。 I have tested it on its own.
我已经对其进行了单独的测试。
function RegisterFunction() {
//Calling the web method
//<-- Some code -->
data = Food_Calorie_Calculator.WebService1.Register(name, password, RegisterFunctionSuccessCallback);
}
function RegisterFunctionSuccessCallback(data) {
document.getElementById("ResultLabel") = data.;
}
Here is my script manager: 这是我的脚本管理器:
<asp:ScriptManager ID="ScriptManger1" runat="Server">
<Services>
<asp:ServiceReference Path="~/RegisterService.asmx" />
</Services>
</asp:ScriptManager>
remove data. 删除数据。 from your code
从你的代码
document.getElementById("ResultLabel") = data;
The problem is was sintax error. 问题是sintax错误。
instead of: 代替:
document.getElementById("ResultLabel") = data;
document.getElementById(“ ResultLabel”)=数据;
it should have been: 应该是:
document.getElementById('ResultLabel').innerHTML = data;
document.getElementById('ResultLabel')。innerHTML =数据;
Note the ' ' instead of " ", as well as the .innerHTML 请注意,“”而不是“”,以及.innerHTML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.