Методы jQuery Page - PullRequest
       1

Методы jQuery Page

1 голос
/ 24 ноября 2010

После прочтения http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/ я посвятил себя попробовать.Теперь я задаюсь вопросом, почему мой Ajax не называется.Большое спасибо!

код позади

TestingAjax.cs

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;

public partial class TestingAjax : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static string GetDate()
    {
        return DateTime.Now.ToString();
    }
}

и TestingAjax.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestingAjax.aspx.cs" Inherits="TestingAjax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>

    <script  type="text/javascript"  language = "javascript" >
        $(document).ready(function () {
            // Add the page method call as an onclick handler for the div.
            $("#Result").click(function () {
                alert("entre en el click:");
                $.ajax({
                    type: "post",
                    url: "TestingAjax.aspx/GetDate",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert("Returning from Ajax");
                        // Replace the div's content with the page method's return.
                        $("#Result").text(msg.d);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
   <div id="Result">Click here for the time.</div>
    </form>
</body>
</html>

1 Ответ

0 голосов
/ 24 ноября 2010

не забудьте установить свойство EnablePageMethods=true в ScriptManager страницы

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...