如何使用JQuery在HTML页面中调用Web服务 [英] how to call webservice in HTML page using JQuery
本文介绍了如何使用JQuery在HTML页面中调用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
谁能告诉我如何在HTML页面中调用Web服务.
我的Web服务中有一种方法,如
公共 布尔选中(字符串 S,字符串 R)
{
如果(S == R)
返回 真;
其他
返回 假;
}
我想在HTML页面中调用此方法.
我认为我们可以使用Java脚本或jQuery来实现.
如果可以通过这两种方式,任何人都可以使用示例进行解释.
解决方案
您可以使用 ^ ]
示例:
var dataString = " +网站+ '}";
.ajax( { 网址:wsUrl, 类型:' POST', 数据:dataString, contentType:" , dataType:" , 成功:功能(结果){ returnVal = result.d; }, 错误:函数(XMLHttpRequest,textStatus,errorThrown){ returnVal = ' '; } }); }
但是,您还必须将C#函数标记为WebMethod.您还有很多工作要做,如果遇到困难,请返回更具体的内容.
您好,
我无法得到..
请找到下面的代码&解决问题
service.cs
< code> [WebMethod(Description =验证登录凭据")]
公共布尔验证(字符串用户名,字符串密码)
{
SqlConnection oCon =新的SqlConnection(ConfigurationManager.AppSettings ["conStr"]);
SqlCommand oCmd =新的SqlCommand(从tbl_LoginInfo中选择LoginPassword,其中UserName =""+ UserName +"",oCon);
oCon.Open();
字符串Temp = oCmd.ExecuteScalar().ToString();
如果(密码==温度)
返回true;
其他
返回false;
}</code>
service.html
< code>
< script type ="text/javascript" language ="javascript">
var Surl ="http://localhost:3031/HTMLService/Service.asmx";
Dear All,
Can anybody tell me how to call web service in HTML page.
I have one method in my web service like
public bool Check(string S,string R)
{
if(S==R)
return true;
else
return false;
}
I would like to call this method in my HTML page.
I think we can achieve this by using Java script or else by jQuery.
If it possible in these two ways can anybody explain this with example.
解决方案
You use .ajax[^]
Example:
var dataString = "{'Site':'" + site + "'}";
.ajax( { url: wsUrl, type: 'POST', data: dataString, contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) { returnVal = result.d; }, error: function (XMLHttpRequest, textStatus, errorThrown) { returnVal = ''; } }); }
But, you''ll also have to mark your C# function as a WebMethod. You''ve got a lot of work to do so come back with something more specific if you get stuck.
Hi,
I am unable to get it..
Please find the code as below & resolve the issue
service.cs
<code>[WebMethod(Description = "Validate the login credentials")]
public bool Validate(string UserName,string Password)
{
SqlConnection oCon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlCommand oCmd = new SqlCommand("select LoginPassword from tbl_LoginInfo where UserName=''"+UserName+"''", oCon);
oCon.Open();
string Temp = oCmd.ExecuteScalar().ToString();
if (Password == Temp)
return true;
else
return false;
}</code>
service.html
<code>
<script type="text/javascript" language="javascript">
var Surl="http://localhost:3031/HTMLService/Service.asmx";
这篇关于如何使用JQuery在HTML页面中调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文