[英]I want to pass the username and password from html file to (webservice )asmx file. what should i use?
<form class="login" id="frmLogIn" method="post" runat="server">
<p class="title"><i class="fa fa-user-o" style="font-size:20px;color:brown"></i> Log in </p>
<input type="text" placeholder="Username" id="txtusername" runat="server"/>
<i class="fa fa-user"></i>
<input type="password" placeholder="Password" id="txtpassword"runat="server"/>
<i class="fa fa-key"></i>
<a href="#">Forgot your password?</a>
<button>
<i class="spinner"></i>
<span class="state" id="btnLogIn" runat="server" onclick="btnLogIn_Click">Log in</span>
</button>
</form>
I want to pass the username and password from html file to (webservice )file.but i don't know how because i'm newbie to asp.net. 我想将用户名和密码从html文件传递到(webservice)file。但是我不知道怎么做,因为我是asp.net的新手。 If i sink the html into the asp file the html interface will change.
如果我将html下沉到asp文件中,则html界面将更改。 i want to use c-sharp for back end what should i use?.
我想将c-sharp用于后端我应该使用什么?
Your html file 您的html文件
$(document).ready(function () {
var validateUsername = $('#validateUsername');
$('#username').keyup(function () {
var t = this;
if (this.value != this.lastValue) {
if (this.timer) clearTimeout(this.timer);
validateUsername.removeClass('error').html('<img src="images/ajax-loader.gif" height="16" width="16" /> checking availability...');
this.timer = setTimeout(function () {
$.ajax({
contentType: "application/json; charset=utf-8",
url: 'ValidateUser.asmx/GetUsernameAvailable',
data: '{username: "'+t.value + '"}',
dataType: 'json',
type: "post",
success: function (j) {
validateUsername.html('I willl have my logic in here for changing the html on the label to reflect success or failure!');
}
});
}, 200);
this.lastValue = this.value;
Asmx File Asmx文件
<%@ WebService Language="C#" Class="ValidateUser" %>
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.Odbc;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using UserSite.DataClasses;
[WebService(Description = "Web services to query Username availability.", Namespace = "http://localhost")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ValidateUser: System.Web.Services.WebService
{
[WebMethod(Description = "Gets the availability of a username.")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetUsernameAvailable(string username)
{
if (username == null)
{
username = "";
}
DbaseExecSpWithReturnValue Sproc = new DbaseExecSpWithReturnValue();
Sproc.SetSp("sp_CheckUsernameAvailable");
Sproc.AddParam(1);
Sproc.AddParam("Username", SqlDbType.Char, username, 20);
int RetVal = Sproc.Execute();
Sproc.Close();
if (RetVal == 0)
{
return @"{""available"": false}";
}
else
{
return @"{""available"": true}";
}
}
}
public bool GetUsernameAvailable(string username)
{
...
return (RetVal == 0) ? false : true;
}
Ajax Above would return boolean value and you call access it in your call function as jd For example, Ajax Above将返回布尔值,您可以在调用函数中以jd的形式调用access,例如,
...
$ajax({
...
success: function (j) {
alert(j.d); // will alert either true or false
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.