AjaxPro.2 与 Jquery 的 Ajax 的混合使用

AjaxPro.2 与 Jquery 的 Ajax 的混合使用 效果相当好,可以随心所欲

//前台 代码 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxPro.aspx.cs" Inherits="AjaxPro_Test" %>

<!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">
    <title></title>
    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function ajaxTest() {
            AjaxPro_Test.AjaxProcTest(ajaxTestCallBack);
        }
        function ajaxTestCallBack() {
            alert('AjaxProcTest');
        }

        function JqueryAjaxTest() {
            $.ajax({
                type: "GET",
                url: "/ajax.asmx/AjaxProcTest",
                contentType: "application/xml",
                dataType: 'html',
                error: function() { alert('error'); },
                success: function(data) {
                    alert(data);
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <input type="button" value="AjaxPro 无参调用" onclick="ajaxTest()" />
        <input type="button" value="JqueryAjax调用" onclick="JqueryAjaxTest()" />
    </form>
</body>
</html>

//后台 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AjaxPro_Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //注册
        AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro_Test));
    }

    [AjaxPro.AjaxMethod]
    public void AjaxProcTest()
    {
        // "AjaxPro 无参调用";
    }
}

//ajax.asmx 的代码
    [WebMethod]
    public string AjaxProcTest()
    {
        return "AjaxProcTest";
    }

这种使用可以兼容ie6,7,8, firFox,Chorme

posted @ 2012-12-17 11:04  challengesoflife  阅读(740)  评论(0编辑  收藏  举报