-
jQuery $.ajax()/$.get() function always get same value for IE
Posted on June 19th, 2014 Add commentsWhen I was trying to use jQuery $.ajax() or $.get() function retrieve some random value from the server side, it’s working fine on firefox or chrome, but not IE. The server side code like below (written in ASP.NET MVC):
1234567public class HomeController : Controller{public ActionResult GetRandomCount(){return Json(new Random().Next(1, 100), JsonRequestBehavior.AllowGet);}}The client side code:
12345678<a href="javascript:void(0)" onclick="CheckCount()">Check Count</a><script>function CheckCount(){$.get('/Home/GetRandomCount', function (data) {alert(data);});}</script>I’m supposed to get a random number every time I click the link, but in IE, always same one returned. Regarding Craic Computing’s Blog, that’s because IE will cache the value first returned, and trade rest requests as identical by default, so it won’t update the value since the request URL never change.
To fix this issue, just disable cache in the jQuery function as following:12345678function CheckCount(){$.ajaxSetup ({cache: false});$.get('/Home/GetRandomCount', function (data) {alert(data);});}
16 views
-
Set “height” property in CSS of a link
Posted on June 25th, 2013 Add commentsBy default, the tag <a> is an inline element, there is no way to set custom height for it. It only changes along with the text size. But you can change it to be block in order to set a custom height like below:
1234a.bigLink {display: block;height: 100px;}
7 views
-
CSS中的id与class小感
Posted on October 14th, 2008 Add comments最近闲来无事,做了一些基于CSS层叠格式的HTML网页。coding中,对id与class两种调用方式偶有小感。
理论上讲,id通常用于定义页面上一个仅出现一次的标记,或称其具有唯一性;而class是用来根据用户定义的标准对一个或多个元素进行定义的,换句话说,具有重复性——可重复使用。
举个简单的例子:1234567<style><!--#abc{color:#ff0000}#def{color:#0000ff}.ghi{background:#000000}--</style><div id="abc" class="ghi">111</div><div id="def" class="ghi">222</div>总的来说,在网页中,如果计划会有许多分项来说明不同问题,一般用id,即使将来增加新分项,也只用增加新id而已;然而如果每个分项都会有一些相同的内容,譬如颜色、表格、字体、分栏等等,使用class会比较有效。
254 views
Recent Comments