这是我的第一个问题。首先,为我“不完美”的英语感到抱歉......
我正在使用 AJAX 开发 ASP.NET MVC 应用程序。
我在 View 中有以下代码:
<% using(Html.BeginForm(null, "Home", FormMethod.Post, new{id="formcpf"})){ %>
<p>
<input name="tipo" type="radio" value="GeraCPF" /> CPF
<input type="radio" name="tipo" value="GeraCNPJ" /> CNPJ
</p>
<p>
<input type="submit" id="sbmt" value="Gerar" /> <br /><br />
<span id="lblCPF" class="respostaBG"></span>
</p>
和以下调用 Ajax 请求的 Javascript:
$(document).ready(function() {
$("form#formcpf").submit(function(event) {
$(this).attr("action", $("input[@name='tipo']:checked").val());
event.preventDefault();
hijack(this, update_sessions, "html");
});
});
function hijack(form, callback, format) {
$.ajax({
url: form.action,
type: form.method,
dataType: format,
data: $(form).serialize(),
success: callback
});
}
function update_sessions(result) {
$("#lblCPF").html(result);
}
在 Firefox 和 Chrome 中工作正常,但在 IE7 中有时会将值返回到标签中,有时不会。我必须继续提交才能获得返回。
有人可以帮忙吗?
请您参考如下方法:
你是否禁用了缓存?
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
此属性位于 Controller 类中,用于禁用缓存。因为我不需要在我的应用程序中缓存,所以我将它放在我的 BaseController 类中:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public abstract class BaseController : Controller
{
这是关于 OutputCacheAttribute 的很好的描述:Improving Performance with Output Caching
检查禁用是否解决了问题。
