我单击我的编辑按钮,它在 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>