易截截图软件、单文件、免安装、纯绿色、仅160KB

ajax请求不返回html代码


ajax请求不返回html代码的三种方式
ajax请求代码:
function ajaxSend() {
$.ajax({
url: “Test_Ajax.aspx”,
type: “post”,
data: { name: “ajax” },//如果请求的自身页面,为了在后台判断是不是ajax请求
error: function(xhr, textStatus, errorThown) {
alert(errorThown);
},
success: function(data) {
alert(data);
}
});
}
1、把.aspx页面的html代码删除,删除后代码如下(ajax请求的不是自身页面)
.aspx页面代码
<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”AjaxReceive.aspx.cs” Inherits=”testJqueryUI.ajax.AjaxReceive” %>
.aspx.cs页面代码如下
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(“love life”);
}
2.通过clear和end方法实现
.aspx.cs代码如下
string name = Request["name"];
//如果请求的是自身页面则需要这一步,判断是不是ajax请求
if (!String.IsNullOrEmpty(name))
{
Response.Clear();
Response.Write(“hello the world”);
Response.End();
}
3、通过实现IHttpModul实现
httpmodul代码如下
public class AjaxModul : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
//throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
context.ReleaseRequestState += AjaxFilter;
}
private void AjaxFilter(object sender, EventArgs e)
{
HttpRequest request = HttpContext.Current.Request;
HttpResponse response = HttpContext.Current.Response;
if (!string.IsNullOrEmpty(request["name"]))
{
HttpResponse reponse1 = HttpContext.Current.Response;
reponse1.Filter = new AjaxResponseFilter(reponse1.Filter);
}
}
#endregion
}
AjaxResponseFilter.cs代码如下
public class AjaxResponseFilter : Stream
{
private readonly StringBuilder html;
private Stream response;
/// <summary>
/// 所有要往页面输出的内容保存在html中
/// </summary>
/// <param name=”buffer”></param>
/// <param name=”offset”></param>
/// <param name=”coun


相关文档:

常用HTML代码速查表


标记或参数
定 义
<A>
连结标记
<ADDRESS>
地址标记(斜体效果)
<AREA>
连结区域标记(设定各连结区域)
alink
点击连结时的样式。例:alink="#FF0000"
align
水平方向摆放位置。例:align="center"
alternate
来回走动,例:behavior=alternate
alt
在连结中插入文字说明。例:alt=" ......

jQuery Ajax之$.get()方法和$.post()方法

注意:$.get()和$.post()方法是jQuery中的全局函数。前面讲到的load()方式是对jQuery对象进行操作的。
1、 $.get()方法
  $.get()方法使用GET方式来进行异步请求。
  它的语法结构为:
  $.get( url [, data] [, callback] [, type] )
  $.get()方法参数解释如下表:
参数名称
类 型
说  明
url
Strin ......

Ajax 操作XML的好实例

  在上一篇文章中,我们讨论了如何通过javascript从一个远程XML文件中取得数据。在这篇文章中,我们将学会怎样对数据作更复杂的处理。作为一个示例,我们会准备一组XML数据,将数据分割成独立的片断并以不同的方式展示这些片断(取决于它们是如何被标识的)。
  这篇文章是建立在上一篇文章中构造的示例代码的基础之上 ......

Struts2 Jquery Json 实现AJax表单验证

弄了一整天了,刚开始学习Jquery,很多东西还不熟,看看视频,查查资料,终于成功的集成Struts2+Jquery+Json
直接上图:用户名输入xxx,焦点丢失,提示”用户已存在“,否则提示“可以注册“,密码同样如此,
首先需要导包:如下除了struts2必须的包外,还有json包以及涉及的commons的几个包.
此外要下 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号