1

我单击我的编辑按钮,它在 javascript 中进入按钮单击功能。执行 ajax() 时,控件转到 WebForm 的页面加载,而不是直接调用我提到的 webform 的 update() [url:“WebForm1.aspx /update",] in ajax()。为什么不调用我的更新函数?我的网络表单有母版页,按钮是 asp:control

This is my javascript
$(document).ready(function () {

    $("input[id*='edit']").click(function () {
        var userdata = {};
        userdata["Name"]="Saran";
        var DTO = { 'userdata' : userdata};
        $.ajax({
            type: "POST",
            contenttype: "application/json; charset=utf-8",
            url: "WebForm1.aspx/update",
            data: JSON.stringify(DTO),
            datatype: "json",
            success: function (result) {
                //do something
                alert("SUCCESS = " + result);
                console.log(result);
            },

            error: function (xmlhttprequest, textstatus, errorthrown) {
                alert(" conection to the server failed ");
                console.log("error: " + errorthrown);
            }
        });//end of $.ajax()

        return false;
    });//eof button click
});


and my webform looks like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using Payoda.Assignments.BusinessLayer;

namespace Payoda.Assignments.LoginApplication
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        [WebMethod]
        public static string update(string userdata)
        {
            return "success";
        }
    }
}


my aspx page looks like this

<%@ Page Title="" Language="C#" MasterPageFile="~/MyMasterPage.Master" AutoEventWireup="true" CodeBehind="TrialPage.aspx.cs" Inherits="Application.TrialPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script src="Scripts/TrialScript.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Contents" runat="server">
    <asp:Button ID="editLink" runat="server" Text="MY BUTTON" />
</asp:Content>
4

2 回答 2

0

我发现了错误... contentType 的 $.ajax 参数之一被错误地写为 contenttype 而正确的格式是“contentType”...

于 2013-10-06T05:01:08.893 回答
0

您应该使用常规的 html 输入而不是 asp:button

于 2017-06-08T14:37:26.060 回答