2010-11-24 4 views
1

http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/を読んだ後、私はそれを自分で試しています。私は今、なぜ私のアヤックスが呼ばれていないのだろうと思っています。どうもありがとう!jQueryページメソッド

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

のにScriptManagerのプロパティEnablePageMethods=trueを設定することを忘れないでください、あなたはより多くを投稿することができますあなたのコードの?おそらく、 "#Result"がクリックイベントを選択してアタッチすることになっている問題です。 – fehays

答えて

-1

の背後にあるコードは、ページ

関連する問題