62,074
社区成员
发帖
与我相关
我的任务
分享
<script language="javascript">
var user_is_exist = false;
function checkname()
{
$.ajax({
type: "get",
url: "Reg.aspx/ajax",
async: false,
dataType: "text", //返回类型是json
contentType:"application/text;",
data: "name=" + $("#username").val(),
async : false,//取消异步,进行同步,进行完ajax在进行下面的ajax
success: function(data) {
if(data=="1")
{
user_is_exist = true;
}else{
user_is_exist = false;
}
}
});
if (!user_is_exist) {
arguments[1].IsValid = false;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
public static object ajax(string str)
{
string name = Request.QueryString["name"].ToString();
if (name == "Microtiger")
{
return "0";
}
else
{
return "1";
}
}
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 PageMethodDemp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageMethodDemp.aspx.cs"
Inherits="PageMethodDemp" %>
<!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="jquery-1.2.6.min.js"></script>
<script>
$(document).ready(function() {
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "PageMethodDemp.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// 使用 Page Method 的返回值来替代 div 的内容
$("#Result").text(msg.d);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="Result">Click here for the time.</div>
</form>
</body>
</html>