GVKun编程网logo

getJSON 缓存(get post缓存)

16

本文的目的是介绍getJSON缓存的详细情况,特别关注getpost缓存的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解getJSON缓存的机会,同时也不会遗漏关于$

本文的目的是介绍getJSON 缓存的详细情况,特别关注get post缓存的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解getJSON 缓存的机会,同时也不会遗漏关于$ .getJSON和$ .get之间的区别、$.get(),$.post(),$.ajax(),$.getJSON()、$.getJson方法清除缓存、$.post() $.get() $.getJSON()的知识。

本文目录一览:

getJSON 缓存(get post缓存)

getJSON 缓存(get post缓存)

方法:在参数中加一个随机数。
例1:
jQuery.getJSON("$!{Root}/a/a/s.ashx",{ID:"123456",Name:"john",random:Math.random()},function(responseText){}
例2:
"xxx.aspx?randID="+Math.random
例3:
"xxx.aspx?randID="+ escape(new Date())
2 将cache设为False
$.ajax不缓存版:
$.ajax({
type:"GET"
url:'test.html',
cache:false,
dataType:"html",
success:function(msg){
alert(msg);
}
});
3.在labels.html文件的顶部加入以下声明:

<Meta HTTP-EQUIV="Pragma" CONTENT="no-cache">

<Meta HTTP-EQUIV="Expires" CONTENT="-1">
4.load函数不仅可以调用HTML,也可以调用script,比如labels.PHP,可以在PHP文件里使用header函数:

<?PHP

header("Cache-Control: no-cache,must-revalidate");

?>
5 使用post代替get方法。
使用Post方式需注意:
设置header的Context-Type为application/x-www-form-urlencode确保服务器知道实体中有参数变量. 通常使用XmlHttpRequest对象的SetRequestHeader("Context-Type","application/x-www- form-urlencoded;")。例:

xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
参数是名/值一一对应的键值对,每对值用&号隔开.如 var name=abc&sex=man&age=18,注意var name=update.PHP?

abc&sex=man&age=18以及var name=?abc&sex=man&age=18的写法都是错误的;
参数在Send(参数)方法中发送,例: xmlHttp.send(name); 如果是get方式,直接 xmlHttp.send(null);

服务器端请求参数区分Get与Post。如果是get方式则$username = $_GET["username"]; 如果是post方式,则$username = $_POST["username"]; 6 在服务端加 header("Cache-Control: no-cache,must-reva lidate"); 7 在ajax发送请求前加上 xmlHttpRequest.setRequestHeader("If-Modified-Since","0"); 8 在ajax发送请求前加上 xmlHttpRequest.setRequestHeader("Cache-Control","no-cache");

$ .getJSON和$ .get之间的区别

$ .getJSON和$ .get之间的区别

这两个电话真的有区别吗?如果使用getJSON,则仍然必须format=json在url中声明…

您可以在中执行相同的操作$.get(),并遍历JSON对象。

还是我要离开这里?

$.get(),$.post(),$.ajax(),$.getJSON()

$.get(),$.post(),$.ajax(),$.getJSON()

一 $.get (url,[data],[callback]) 说明:url 为请求地址,data 为请求数据的列表,callback 为请求成功后的回掉函数,该函数接收两个参数,第一个为服务器返回的数据;第二个参数为服务器的状态,是可选参数。

$.getJson方法清除缓存

$.getJson方法清除缓存

$.getJson方法当重复请求同一页面时,只从缓存中加载数据,要想每次重新加载需要将URL后面跟动态参数

$.getJson("a.ashx?t="+new Date(),"{a:b}",fun....)

在参数列表中改变参数无效。

$.post() $.get() $.getJSON()

$.post() $.get() $.getJSON()

HTML+JS代码

<html> <head> <title></title> <script src=jquery⑵.1.3.js></script> </head> <body> <div id=UserName></div> <div id=Age></div> <div id=Gender></div> </body> </html> <script type=text/javascript> //$.post(url,[data],[callback],[type]) 1:地址 2:参数 3:回调函数 4:要求完成后返回的数据类型 $.post(Handler1.ashx,function (data) { data = $.parseJSON(data); $(#Gender).text(data.JsonData[2].Gender); }) //由于这里没有设置第4个参数,所以data仅仅是1个字符串,那末我们就需要利用$.parseJSON()方法将data字符串转换成json对象 //$.get(url,[type]) 1:地址 2:参数 3:回调函数 4:要求完成后返回的数据类型 $.get(Handler1.ashx,function (data) { console.info(data,data); //输出:{ JsonData: [{ UserName: 张3},{ Age: 25 },{ Gender: 男 }]} $(#UserName).text(data.JsonData[0].UserName); },json); //这个json是设置获得数据的类型,所以得到的数据格式为json类型的(可选参数) //$.getJSON(url,[callback]) 1:地址 2:参数 3:回调函数 $.getJSON(Handler1.ashx,function (data) { $(#Age).text(data.JsonData[1].Age); //无需设置,$.getJSON获得的数据类型为直接为json, }) </script>

1般处理程序

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1 { /// <summary> /// Handler1 的摘要说明 /// </summary> public class Handler1 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = text/html; var Json = {JsonData:[{UserName:张3},{Age:25},{Gender:男}]}; context.Response.Write(Json); } public bool IsReusable { get { return false; } } } }



总结

以上是小编为你收集整理的$.post() $.get() $.getJSON()全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

今天关于getJSON 缓存get post缓存的分享就到这里,希望大家有所收获,若想了解更多关于$ .getJSON和$ .get之间的区别、$.get(),$.post(),$.ajax(),$.getJSON()、$.getJson方法清除缓存、$.post() $.get() $.getJSON()等相关知识,可以在本站进行查询。

本文标签: