Monday

asp.net jquery ajax data webmethod post


1.Code - behind class
  
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Modules.MembershipModule;

namespace VoluntaryShop
{
public partial class jsonhub : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string Test()
{
return "OK";
}

[WebMethod]
public static ArrayList MSearchVolunteersbyGroup(int Group)
{
Debug.Write("MSearchVolunteersbyGroup"+Group);
MembershipModuleController c = new MembershipModuleController();
return c.MSearchVolunteersbyGroup(Group);
}
}
}


2.ASPX Page:
   
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jsonhub.aspx.cs" Inherits="VoluntaryShop.jsonhub" %>
<!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 type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"> </script>
<script type="text/javascript">
function PageMethod(fn, paramArray, successFn, errorFn) {
var pagePath = window.location.pathname;
//Create list of parameters in the form:
//{"paramName1":"paramValue1","paramName2":"paramValue2"}
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
if (paramList.length > 0) paramList += ',';
paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
}
}
paramList = '{' + paramList + '}';
//Call the page method
$.ajax({
type: "POST",
url: pagePath + "/" + fn,
contentType: "application/json; charset=utf-8",
data: paramList,
dataType: "json",
success: successFn,
error: errorFn
})
;
}
</script>

<script type="text/javascript">


function AjaxSucceeded(result) {
alert(result.d);
alert(result.d[0].FirstName);

}
function AjaxFailed(result) {

alert("failed"+result.d);
}

PageMethod("MSearchVolunteersbyGroup", ["Group","1"], AjaxSucceeded, AjaxFailed); //No parameters
</script>


</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...