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
相关文档:
最近网上提的很多的一个新概念就是 AJAX 了, 那么, AJAX 是什么呢? 以下内容引用网上资料:
AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。它有机地包含了以下几种技术:
Ajax(Asynchronous JavaScript + XML)的定义
基于 web标准(sta ......
到最后我才发现微软给的ajax json 实例都是有问题的,很多都是不严密的,特别是对于大小写方面,他们都没有仔细追究大小写问题,导致了在firefox使用有问题。下面是实例内用:两个html之间的:
<head> <title>测试ajax</title> <meta http-equiv=”Content-Type” content=”text/ht ......
代码下载:http://code.google.com/p/ajaxautocomplete/downloads/list
Auto Complete的jQuery控件。
首先是需要设计下我们的DIV最后应该显示成什么样子,我的CSS不咋地。瞎玩呢。样子如下:
首先是一个DIV,然后是添加一个ul和几个li tag:
<div id="nav">
<ul>
<li><a>Text1 field1& ......
1创建两张页面 Reg.aspx、CallServer.aspx。
在Reg.aspx页面的html中放 一个层和一个文本框
<div id="aa">
<asp:TextBox id="txtuser" runat="server" Width="136px"></asp:TextBox>
</div>
<span id="errInfo">请输入用户名</span>
在Reg.aspx页面中写javascript
定义二个变量 ......