在我的网页中,我有一个显示System.Text.StringBuilder csv = new System.Text.StringBuilder();
String separator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
List<String> listProperties = new List<string>();
csv.AppendLine("sep=" + separator);
foreach (System.Windows.Controls.GridViewColumn col in myGridView.Columns)
{
// Check if column is displayed
if (col.ActualWidth > 0)
{
// Get Header value
string header = col.Header as String;
//Check if Header is not empty
if (!String.IsNullOrWhiteSpace(header))
{
// Write in firte line
csv.Append(header + separator);
// Get if columns is binding a property
System.Windows.Data.Binding binding = col.DisplayMemberBinding as System.Windows.Data.Binding;
if (binding != null)
{
// Get the name of property
listProperties.Add(binding.Path.Path);
}
}
}
}
// Write first line
csv.AppendLine();
foreach (myItem item in myListView.Items)
{
foreach (String property in listProperties)
{
// Get and write value for property
object value = GetPropValue(item, property);
csv.Append(value + separator);
}
csv.AppendLine();
}
System.IO.File.WriteAllText(path, csv.ToString());
public static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
代码的img
和一个captcha
代码,用于在点击时刷新img
代码,而不是整页。在captcha
中,它可以很好地运行并在每次点击时刷新代码,但在chrome
点击IE
时没有任何反应,并且用于刷新img
代码重新加载页面。
如何在captcha
?
IE
脚本:
<img name="capImg" id="capImg" src="php/captcha.php">
<img src="images/recaptcha.png" onClick="resetCap();">
captcha.php:
function resetCap(){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
document.getElementById('capImg').src = "php/captcha.php";
}
}
ajaxRequest.open("GET", "php/captcha.php", true);
ajaxRequest.send();
}
答案 0 :(得分:1)
使用一个唯一的参数,使浏览器再次检索图像,而不是查看缓存。你不需要Ajax:
function resetCap(){
document.getElementById('capImg').src =
"php/captcha.php?" + new Date().getTime();
}
这就是你所需要的一切。