前台JQuery方式的Ajax代码:

View Code
    <script type="text/javascript">
        $(function () {
            $("#btnAddNews").bind("click", function () {
                var title = $.trim($("#txtNewTitle").val());
                var content = $("#<%=fckNewsContent.ClientID %>").val();
                $.ajax({
                    type: "POST",
                    url: "AddNews.aspx/addNew",
                    data: "{'title':'" + title + "','content':'" + content + "'}",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        alert(data.d);
                    },
                    error: function (err) {
                        alert(err);
                    }
                });
            });
        });
    </script>


后台demo.aspx.cs的代码:

View Code
        [WebMethod]
        public static string addNew(string title, string content)
        {
            return title + content;
        }

 

相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2021-06-27
  • 2021-09-22
  • 2021-05-28
猜你喜欢
  • 2021-11-19
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-07-24
相关资源
相似解决方案