1 回答
TA贡献1891条经验 获得超3个赞
被大佬解惑,是因为jQ缓存了GET请求的结果,这里贴上大佬的回答,感谢JLRishe的回复:
Most likely, the response is being cached because it is a GET request. Try telling jQuery to disable the cache:
$.ajax( {
type: "get",
url: "/getNickname",
cache: false, // <--- here
data: {
//index: i //my solution
},
beforeSend: function ( request ) {
},
success: function ( res ) {
console.log( "test response is ", JSON.stringify( res ) );
},
error: function ( err ) {
reject( err );
}
} );
另付jq文档关于cache选项的说明:
cache (default: true, false for dataType 'script' and 'jsonp')
Type: Boolean
If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.
添加回答
举报