Stack Exchange MiniProfiler 不显示配置文件框?
我已经安装了 Stack Exchange MiniProfiler,并且“查看源代码”显示它正在呈现预期的 HTML。然而,它没有显示角落里的小轮廓细节框 - 可能出了什么问题?
<script src="/v2/Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/v2/mini-profiler-includes.css?v=1.7.0.0">
<script type="text/javascript" src="/v2/mini-profiler-yepnope.1.0.1.js"></script>
<script type="text/javascript">
yepnope([
{ test: window.jQuery, nope: '/v2/mini-profiler-jquery.1.6.1.js' },
{ test: window.jQuery && window.jQuery.tmpl, nope: '/v2/mini-profiler-jquery.tmpl.beta1.js' },
{ load: '/v2/mini-profiler-includes.js?v=1.7.0.0',
complete: function() {
jQuery(function() {
MiniProfiler.init({
ids: ["025bbb91-9605-44b7-b33d-d8b196326dbc","2c74ce3e-8de6-4f8d-920a-e8708b22231b"],
path: '/v2/',
version: '1.7.0.0',
renderPosition: 'left',
showTrivial: false,
showChildrenTime: false,
maxTracesToShow: 15
});
});
}
}]);
</script>
在我的 Global.asax.cs 中:
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
编辑:感谢 Sam 的输入,我已将问题跟踪到我的 .ajaxSetup() 方法。当它被注释掉时,配置文件框会再次显示。但我不明白为什么这是一个问题:
$.ajaxSetup({
data: "{}",
dataFilter: function (data) {
var msg;
if (data == "") {
msg = data;
}
else if (typeof (JSON) !== 'undefined' && typeof (JSON.parse) === 'function') {
msg = JSON.parse(data);
}
else {
msg = eval('(' + data + ')');
}
if (msg.hasOwnProperty('d')) {
return msg.d;
}
else {
return msg;
}
}
});
I've installed the Stack Exchange MiniProfiler, and View Source shows that it is rendering the expected HTML. However it does not show the little profile detail box in the corner - what could be wrong?
<script src="/v2/Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/v2/mini-profiler-includes.css?v=1.7.0.0">
<script type="text/javascript" src="/v2/mini-profiler-yepnope.1.0.1.js"></script>
<script type="text/javascript">
yepnope([
{ test: window.jQuery, nope: '/v2/mini-profiler-jquery.1.6.1.js' },
{ test: window.jQuery && window.jQuery.tmpl, nope: '/v2/mini-profiler-jquery.tmpl.beta1.js' },
{ load: '/v2/mini-profiler-includes.js?v=1.7.0.0',
complete: function() {
jQuery(function() {
MiniProfiler.init({
ids: ["025bbb91-9605-44b7-b33d-d8b196326dbc","2c74ce3e-8de6-4f8d-920a-e8708b22231b"],
path: '/v2/',
version: '1.7.0.0',
renderPosition: 'left',
showTrivial: false,
showChildrenTime: false,
maxTracesToShow: 15
});
});
}
}]);
</script>
And in my Global.asax.cs:
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
EDIT: Thanks to Sam's input I've tracked the problem to my .ajaxSetup() method. When it is commented out the profile box shows again. But I can't see why this is a problem:
$.ajaxSetup({
data: "{}",
dataFilter: function (data) {
var msg;
if (data == "") {
msg = data;
}
else if (typeof (JSON) !== 'undefined' && typeof (JSON.parse) === 'function') {
msg = JSON.parse(data);
}
else {
msg = eval('(' + data + ')');
}
if (msg.hasOwnProperty('d')) {
return msg.d;
}
else {
return msg;
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是全局 dataFilter 干扰了 MiniProfiler 的 jQuery Templates 模板文件的
$.get()
。在 HTML 片段上调用 JSON.parse() 肯定会抛出错误。由于您使用的是最新版本的 jQuery,因此不需要手动添加优化的 JSON 解析。该功能已包含在 1.4 的 jQuery 核心中。
因此,最简单的是,尝试将全局 dataFilter 更改为:
如果这不能解决问题,您可能需要研究 jQuery 1.5 的转换器而不是全局 dataFilter,它允许您将类似 dataFilter 的操作应用于响应某些内容类型。来自实际进行 jQuery 1.5 AJAX 重写的人的一些很好的例子:http://encosia.com/jquery-1-5s-ajax-rewrite-and-asp-net-services-all-is-well/#comments
My guess is that the global dataFilter is interfering with MiniProfiler's
$.get()
for jQuery Templates template files. CallingJSON.parse()
on an HTML fragment will definitely throw an error.Since you're using a recent version of jQuery, the optimized JSON parsing isn't something you need to add manually. That functionality was included in jQuery core in 1.4.
So, most simply, try changing your global dataFilter to this:
If that doesn't fix it, you might want to look into jQuery 1.5's converters instead of the global dataFilter, which allow you to apply a dataFilter-like operation to responses of certain Content-Type. Some good examples from the guy that actually did the jQuery 1.5 AJAX rewrite here: http://encosia.com/jquery-1-5s-ajax-rewrite-and-asp-net-services-all-is-well/#comments
这是有道理的,也许你的过滤器正在破坏结果。
如果您看到它是 MiniProfiler JSON 结果,则添加绕过过滤的条件应该可以修复它。
This sort of makes sense, perhaps your filter is mangling the results.
Adding a conditional that bypasses the filtering if you see it is a MiniProfiler JSON result should fix it.