我应该使用POST或检索JSON数据到jqGrid的在我的ASP.NET MVC应用程序时得到什么呢? [英] Should I be using POST or GET when retrieving JSON data into jqGrid in my ASP.NET MVC application?

查看:150
本文介绍了我应该使用POST或检索JSON数据到jqGrid的在我的ASP.NET MVC应用程序时得到什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 jqGrid的在我的ASP.NET MVC应用。目前,我有M型:POST是这样的:

I am using jqgrid in my ASP.NET MVC application. Currently I have mTYpe: 'POST' like this:

jQuery("#myGrid").jqGrid({
    mtype: 'POST',
    toppager: true,
    footerrow: haveFooter,
    userDataOnFooter: haveFooter,

不过,我读这文章,我看到这一段:

浏览器可以缓存图片,JavaScript,CSS文件在用户的硬盘   驱动器,而且还可以缓存XML HTTP调用如果调用是一个HTTP GET。   高速缓存是基于该URL。如果是相同的URL,它的缓存   在计算机上,则响应从缓存加载,而不是从   它再次请求时服务器。基本上,浏览器可以   缓存任何HTTP GET调用和返回基于URL的缓存数据。如果   你让一个XML HTTP调用作为HTTP GET和服务器返回一些   特殊的头它通知浏览器缓存响应,上   将来调用,响应将立即从高速缓存返回的   从而节省了网络往返和下载时间的延迟。

Browsers can cache images, JavaScript, CSS files on a user's hard drive, and it can also cache XML HTTP calls if the call is a HTTP GET. The cache is based on the URL. If it's the same URL, and it's cached on the computer, then the response is loaded from the cache, not from the server when it is requested again. Basically, the browser can cache any HTTP GET call and return cached data based on the URL. If you make an XML HTTP call as HTTP GET and the server returns some special header which informs the browser to cache the response, on future calls, the response will be immediately returned from the cache and thus saves the delay of network roundtrip and download time.

鉴于这种情况下,我应该切换我jqGrid的M型都使用来自POST,GET为MTYPE? (它说,XML(没有提到JSON)。如果答案是肯定的,那么实际上会是什么一个情况,为什么我会永远想使用POST进行jqGrid的M型,因为它似乎做同样的事情,如果没有这个缓存的好处?

Given this is the case, should I switch my jqGrid mType all to use "GET" from "POST" for the mType? (It says XML (doesn't mention JSON). If the answer is yes, then actually what would be a situation why I would ever want to use POST for jqGrid mType as it seems to do the same thing without this caching benefit?

推荐答案

您描述可以在Internet Explorer中,但是的它会不会在jqGrid的存在,如果你使用默认选项的问题

The problem which you describe could be in Internet Explorer, but it will be not exist in jqGrid if you use default options.

如果你将要使用你会看到这样的参数的完整URL

If you look at the full URL which will be used you will see parameters like

nd=1339350870256

它具有相同的含义缓存:真正的中的 jQuery.ajax 。 jqGrid的当前timestemp添加到URL,使其独特的。

It has the same meaning as cache: true of jQuery.ajax. jqGrid add the current timestemp to the URL to make it unique.

我个人比较喜欢使用HTTP GET在jqGrid的,但我不喜欢第二参数的用法。我在老答案。这将是更好地使用 prmNames:{ND:空} jqGrid的的选项,删除第二参数的用法该网址。而不是一个可以的控制在服务器端缓存的。例如设置

I personally like to use HTTP GET in jqGrid, but I don't like the usage of nd parameter. The reason I described in the old answer. It would be better to use prmNames: {nd:null} option of jqGrid which remove the usage of nd parameter in the URL. Instead of that one can control the caching on the server side. For example the setting of

Cache-Control: private, max-age=0

是我的标准设置。要设置你只需要包含在ASP.NET MVC行动code以下行的HTTP标头

is my standard setting. To set the HTTP header you need just include the following line in the code of ASP.NET MVC action

HttpContext.Current.Response.Cache.SetMaxAge (new TimeSpan (0));

您可以在答案。

重要的是要明白,此时的标题缓存控制:私人,最大年龄= 0 不要prevent数据的缓存,但数据将永远不会使用在服务器上重新验证。使用其他HTTP标头选项 ETag的可以使重新验证真正的工作。其主要思想,即的ETag值将被永远改变了更改服务器上的数据。在如果previous数据已经在网络浏览器缓存中的网页浏览器的自动发送如果 - 无 - 匹配参与的情况下,与的ETag 从缓存数据的价值HTTP请求。因此,如果服务器看到的数据没有改变它可与具有 304未修改状态和空身 HTTP响应的HTTP响应回答。它允许Web浏览器使用本地previously缓存数据。

It's important to understand, that the header Cache-Control: private, max-age=0 don't prevent the caching of data, but the data will be never used without re-validation on the server. Using other HTTP header option ETag you can make the revalidate really working. The main idea, that the value of ETag will be always changed on changing the data on the server. In the case if the previous data are already in the web browser cache the web browser automatically send If-None-Match part in the HTTP request with the value of ETag from the cached data. So if the server see that the data are not changed it can answer with HTTP response having 304 Not Modified status and empty body of the HTTP response. It allows the web browser to use local previously cached data.

答案和的这个你会发现code示例演示如何使用的ETag 办法。

In the answer and in this one you will find the code example how to use ETag approach.

这篇关于我应该使用POST或检索JSON数据到jqGrid的在我的ASP.NET MVC应用程序时得到什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆