Myeclipse+Ajax 例子
一个MyEclipse里的AJAX例子2008-03-19 19:53本例将在页面的参数以Get和POST两种方式传递到服务器,并回显到页面; 本例共包括两个主要文件getAndPostExample.html和GetAndPostExample.java以及一个配置文件web.xml 建立文件的步骤: 1.在Eclipse新建一个web project-->ajax1 2.在ajax1里面新建一个getAndPostExample.html 3.在ajax1里面新建一个servlet-->GetAndPostExample.java getAndPostExample.html如下
This is the description of my J2EE component This is the display name of my J2EE component GetAndPostExample com.ajax1.GetAndPostExample GetAndPostExample /GetAndPostExample index.jsp 在这个简单的AJAX的例子里getAndPostExaple.html负责表单参数的输入和传递,而servlet GetAndPostExample.java负责在服务器端接受参数。参数传递时加的时间戳是保证URL的唯一性。
相关文档:
以前提交表单的方法是submit,但是这样的话无法使用Ajax,一提交就意味着需要刷新页面。另一种方法是在url上面加上parameter来发送表单,但是这样会暴露发送的内容。但是如果用Ajax发送表单的话就能避免上面两种问题。
但是我之前自己写的时候,总是提交的是null值,运 ......
打开请求
有了要连接的 URL 后就可以配置请求了。可以用 XMLHttpRequest 对象的 open() 方法来完成。该方法有五个参数:
request-type:发送请求的类型。典型的值是 GET 或 POST,但也可以发送 HEAD 请求。
url:要连接的 URL。
asynch:如果希望使用异步连接则为 true,否则为 false。该参数是可选的,默认为 true。
......
Private static readonly object ReflectionLock = new object();
Lock (ReflectionLock)
{
Type scriptManagerType =
Type.GetType(
"System.Web.UI.ScriptManager, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35",
false);
......
ashx文件是.net 2.0新加的文件类型(其实在.net 1.0下已经可用,但是没有公开提供).
ashx文件和aspx文件有什么不同? 我们先新建一个ashx文件看看:
ashx
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void Process ......
把自己写的jquery写下来
比如现在有一个界面,分左右两侧,当点击左侧的标签,然后在右侧框显示,实现无刷新技术,这是最简单的ajax应用
function touser() {
$.ajax({
url: "UserTable.aspx?timeStamp=" + new Date().getTime(),
success: function(msg) {
$("#ma ......