Jquery无法调用C#函数 [英] Jquery fail to call C# function

查看:64
本文介绍了Jquery无法调用C#函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication10._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
    $(document).ready(function () {
        $("#userinput").on('input', function () {
            if ($(this).val().length >= 8) {
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/fillfields",
                    contentType: "application/json; charset=utf-8",
                    data: '{employeeID: "' + $("#userinput").val() + '"}',
                    dataType: "json"
                });
                $('#userinput').val("");
            }
        });
    });

    </script>
    <br>
    <div style="text-align: center">
        <br>
        <input autofocus="autofocus"  id="userinput" />
        <br>
        <hr>
    </div>







using System;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication10
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        [System.Web.Services.WebMethod]
        public static void fillfields(string employeeID)
        {
            string constr = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(constr))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("TMS_INSERT", connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@EMP_ID", employeeID);
                    command.ExecuteNonQuery();
                }
                connection.Close();
            }
        }
    }
}



为什么我的代码无法调用c#函数?代码看起来很好但是失败了工作:(



我尝试过:



请帮忙并指导我,尝试查看broswer控制台,但其空白


why my code fail to call the c# function?code look fine but fail to work : (

What I have tried:

please help and guide me,tried look into broswer console but its blank

推荐答案

文档)。ready(< span class =code-keyword> function (){
(document).ready(function () {


#userinput)。on(' input' function (){
if
("#userinput").on('input', function () { if (


this )。val()。length> = 8 ){
(this).val().length >= 8) {


这篇关于Jquery无法调用C#函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆