[英]Asp.Net Web Service problem
I have a problem regarding with asp.net web service.I have a register.aspx page.我对 asp.net web 服务有疑问。我有一个 register.aspx 页面。 I want to do thing,if there is already a record which entry to the inside of text field during the process of register,I want to give a alert to me.我想做的事情,如果在注册过程中已经有记录进入文本字段内部,我想给我一个警报。
I'm using jquery for that.I wrote those codes by creating web service.However,it can't find to the webservice.What should I do?我为此使用 jquery。我通过创建 web 服务编写了这些代码。但是,它找不到 web 服务。我该怎么办?
Here is my code.这是我的代码。
Web service: Web服务:
[WebMethod]
public int CheckUser(string username)
{
string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
string query = String.Format("select COUNT(*) from Users where Username='{0}'", username);
SqlConnection baglan = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(query, baglan);
baglan.Open();
int result = (int)cmd.ExecuteScalar();
baglan.Close();
return result;
}
Register.aspx:注册.aspx:
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#Txtuname").change(CheckUser);
});
function CheckUser() {
//alert("test");
$.ajax({
type: "POST",
url: "WebService1/Service1.asmx/CheckUser",
data: "{username: '" + $('#Txtuname').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#duplicate").empty();
if (response.d != "0") {
$("#duplicate").html(' That user name has already been taken');
}
}
});
}
</script>
Related Field:相关领域:
<tr>
<td>
<span class="label">Username:</span>
</td>
<td>
<asp:TextBox ID="Txtuname" runat="server"></asp:TextBox><span id="duplicate"></span>
</td>
</tr>
Use /WebService1/Service1.asmx/CheckUser
if your web service is located at the root of your application.如果您的 web 服务位于应用程序的根目录,请使用/WebService1/Service1.asmx/CheckUser
。 Otherwise, please show us the file-system structure of your project.否则,请向我们展示您项目的文件系统结构。
Hint: Always copy the path of the current web service, remove the method name and append it to the end of the URL.提示:始终复制当前 web 服务的路径,去掉方法名和 append 到 URL 的末尾。 If it's found, then everything is OK.如果找到了,那么一切正常。 For example, in your case, follow these steps:例如,在您的情况下,请按照下列步骤操作:
/WebService1/Service1.asmx/CheckUser
抓取web服务路径: /WebService1/Service1.asmx/CheckUser
/WebService1/Service1.asmx
从中删除方法名称: /WebService1/Service1.asmx
http://www.site.com/WebService1/Service1.asmx
otherwise, append it to the current path of your current URL (URL of your current page) http://www.site.com/pageName.aspx/WebService1/Service1.asmx
If it starts with / , simply append it to the root path of your site: http://www.site.com/WebService1/Service1.asmx
otherwise, append it to the current path of your current URL (URL of your current page ) http://www.site.com/pageName.aspx/WebService1/Service1.asmx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.