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
相关文档:
META是用来在HTML文档中模拟HTTP协议的响应头报文。META标签用于网页的与中,META标签的用处很多。META的属性有两种:name和http-equiv。name属性主要用于描述网页,对应于content(网页内容),以便于搜索引擎机器人查找、分类(目前几乎所有的搜索引擎都使用网上机器人 ......
jQuery 是什么?
请访问 Ajax 技术资源中心,这是有关 Ajax 编程模型信息的一站式中心,包括很多文档、教程、论坛、blog、wiki 和新闻。任何 Ajax 的新信息都能在这里找到。
jQuery 由 John Resig 创建于 2006 年初,对于任何使用 JavaScript 代码的程序员来说,它是一个非常有用的 JavaScript 库。无论您是刚刚接触 Java ......
在上一篇文章中,我们讨论了如何通过javascript从一个远程XML文件中取得数据。在这篇文章中,我们将学会怎样对数据作更复杂的处理。作为一个示例,我们会准备一组XML数据,将数据分割成独立的片断并以不同的方式展示这些片断(取决于它们是如何被标识的)。
这篇文章是建立在上一篇文章中构造的示例代码的基础之上 ......
13.HTML 图像
图像标签(<img>)和源属性(Src)
在 HTML 中,图像由 <img> 标签定义。
<img> 是空标签,意思是说,它只包含属性,并且没有闭合标签。
要在页面上显示图像,你需要使用源属性(src)。src 指 "source"。源属性的值是图像的 URL 地址。
定义图像的语法是:
<img src="url" />
......
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
定义二个变量 ......