将jQuery应用于Asp.net Ajax时,应避免的3个错误
3 mistakes to avoid when using jQuery with ASP.NET AJAX
AJAX, ASP.NET, JavaScript, jQuery By Dave Ward on June 5th, 2008
Over the past few weeks, I think I have definitely embodied Jeff Atwood’s claim that we’re all amateurs, learning together. Despite my best efforts to thoroughly test before posting, a few problems slipped through in my recent posts about using jQuery to consume ASP.NET JSON serialized web services and using jQuery to call ASP.NET AJAX page methods.
On the bright side, your great feedback in both posts’ comments has reinforced the fact that some of the best content on my blog is the part that you write.
In this post, I’m going to detail three of the problems that were discovered as a result of those previous two posts:
An extra requirement when making a read-only request to IIS6+.
An oddity in Internet Explorer 7’s XmlHttpRequest class.
A common mistake when passing JSON parameters through jQuery.
Finally, I’ll suggest what I now believe to be a best practice usage, taking all of these issues into account.
Security requirements when POSTing to IIS
This error message was the most common problem that was reported:
Length Required
The underlying issue is that most installations of IIS6+ require a content-length be provided with all POST requests, even if there is no content (POST data).
The content-length for a request with no data should be 0, but jQuery doesn’t set that header automatically unless there is a data parameter. Since ASP.NET AJAX’s JSON serialized services require a POST request, this becomes a stumbling block for read-only requests.
The easiest way I’ve found to work around this is to use an empty JSON object as a parameter on read-only requests. For example, if you were calling a page method:
$.ajax({
type: "POST",
url: "PageMethod.aspx/PageMethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
This will c
相关文档:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sy ......
要想了解asp.net 2.0的异步页的处理过程,先列出页面的生命周期:
1 :Init 事件: 页面初始化 ,初始化设置。
2: LoadViewState方法: 加载视图状态, 填充ViewState属性。
3 :LoadPostData方法: 处理回发数据, 处理传入窗体数据。
4: Load 事件: 加载页面 ,页面控件初始化完成并反映了客户端的数据。
5 :Ra ......
本文介绍两种ASP.Net项目中全局变量使用的方式。web.config文件 和 Gloab文件。以下分别说明:
方法一:web.config文件
——设置:
在web.config文件里添加关键字key是通过<appSettings>标记来实现的,但是appSettings标记通常放在<system.web>.....</system.web>标记外面。例:
<conf ......