如何使用jquery调用rest服务? [英] How to call rest service using jquery?
问题描述
我是jquery的新手..我的服务不是在打电话。我不知道如何解决这个问题。
任何人都可以帮我出去
问候,
gayathri reddy
我尝试过:
$(document).ready(function(){
$('#btnSubmit')。click(function(event){
调试器
var url =http:// localhost:35013 / UserService.svc / ValidateUser /+ $('#sender-email')。val()+/+ $( '#user-pass')。val();
$ .getJSON(url,function(data){
if(data) .ValidateUserResult.length> 0){
alert(登录);
}
});
});
});
[ServiceContract]
public interface IUserService
{
[OperationContract]
[WebInvoke(Method =GET,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate =ValidateUser / {LoginID} / {Password})]
用户ValidateUser(字符串LoginID,字符串密码);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required) )]
公共类UserService:IUserService
{
public User ValidateUser(string LoginID,string Password)
{
Membership.ValidateUser(LoginID,密码);
用户_obj =新用户();
_obj.LoginID = LoginID;
返回_obj;
}
}
Hi ,
I am new to jquery ..my service is not calling .i dono how to resolve this.
Any one can help me out
Regards,
gayathri reddy
What I have tried:
$(document).ready(function () {
$('#btnSubmit').click(function (event) {
debugger
var url = "http://localhost:35013/UserService.svc/ValidateUser/" + $('#sender-email').val() + "/" + $('#user-pass').val();
$.getJSON(url, function (data) {
if (data.ValidateUserResult.length > 0) {
alert("logged in");
}
});
});
});
[ServiceContract]
public interface IUserService
{
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "ValidateUser/{LoginID}/{Password}")]
User ValidateUser(string LoginID, string Password);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class UserService : IUserService
{
public User ValidateUser(string LoginID, string Password)
{
Membership.ValidateUser(LoginID, Password);
User _obj = new User();
_obj.LoginID = LoginID;
return _obj;
}
}
推荐答案
(文档)。 ready(function(){
(document).ready(function () {
('#btnSubmit')。click(function(event){
调试器
var url =http:// localhost:35013 / UserService.svc / ValidateUser /+
('#btnSubmit').click(function (event) {
debugger
var url = "http://localhost:35013/UserService.svc/ValidateUser/" +
('#sender-email')。 val()+/+
('#sender-email').val() + "/" +
这篇关于如何使用jquery调用rest服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!