将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
相关文档:
在做ASP项目的时候,判断用户是否登陆常用的方法是在每个页面判断session是否存在,
无奈用java的时候过滤器就用的不熟。。。还是用继承吧。汗。。。
新建一个类
Csharp 代码
using System;
using System.Web;
using System.Web ......
如何在客户端直接调用WebService中的方法?
这里结合经验自己写一写
1.首先新建一个 ASP.NET AJAX-Enabled Web Site,这样系统为我们自动配置好了环境,这主要体现在Web.config这个文件上,如果已有网站不是ASP.NET AJAX-Enabled Web Site也可以对照修改下Web.config,也可以达到相同的效果。
2.新建一个web服务,WebSer ......
1.简单验证
在ASP.Net MVC中,验证是在Controller层,而错误呈现是在View层,Controller层是通过ModelState属性进行验证的,ModelState的状态是通过AddModelError()方法进行 添加的。
而在View层,是通过Html的辅助方法进行呈现的,这两个辅助方法分别是
Html.ValidationMessage()
Html.ValidationSummary()
Controller ......
JSON Serialization and Deserialization in ASP.Net
I was looking around for a simple example which would just do an object serialization to a JSON format, and then deserializing back to the original object. I found few examples on MSDN, but did seem to be too long ......
ASP.NET页面跳转有什么方法呢?,现在给大家介绍三种方法,他们的区别是什么呢?让我们开始吧:
ASP.NET页面跳转1、response.redirect 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次postback),但他可以跳转到任何页面,没有站点页面限制(即可以由雅虎跳到新浪),同时不能跳过登录保护。但速度慢是其最大缺陷! ......