Jquery ajax 初探
初学JQUERY AJAX使用,不知道怎么实现,找了半天资料都差不多,可是放到我的页面里就是不返回值,后来发现因为没往后台页面传值的原因,加了 data: "name=John&location=Boston"就好用了,这里data:""可为任意值,后台并没有接收。
下面是例子,实现的是获取服务器时间并更新
前台代码:
function getServerTime()
{
$.ajax({
type: "POST",
url: "Default2.aspx",
data: "name=John&location=Boston",
success: function(msg){
$("#txtserver").text(msg);
}
});
setTimeout('getServerTime()',500);
}
前台代码2:使用Post方法
function getServerTime()
{
$.get("Default2.aspx?1",function(msg){
$("#txtserver").text(msg);});
setTimeout('getServerTime()',500);
}
后台Default2.aspx
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(DateTime.Now.ToLongTimeString());
}
相关文档:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<titl ......
复杂数据类型使用基础
•公有属性或公有Field会被释放和接受
•容器对象
–实现IList接口的对象
–实现IDictionary接口的对象
•Key必须是String
WebService2.cs Code:
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Service ......
页面文件类似:
<% using (Ajax.BeginForm("AjaxUpdate", 123, new AjaxOptions {
Confirm = "confirm str", LoadingElementId = "idLoading", UpdateTargetId
= "textEntered", OnSuccess = "validateForm" },new{id="idMyForm"}))
&nbs ......