在我的MVC应用程序中,我返回一些Javascript。 Howveer,我使用视图上的防伪标记,所以呈现的结果将是使用MVC3,如何让浏览器明确地将传输的脚本解释为HTML?
// Here, we ensure that jQuery is loaded then load up the rest of our JS in in order.
ord = Math.random() * 10000000000000000;
...
所以有一些HTML添加到页面,则JS。
的问题是,我得到在Chrome以下通知:
资源解释为脚本,但使用MIME类型传输
我需要的浏览器,以便作出解释为HTML使用防伪标记。
我试图把这种对视图:
这使得:
...
...但同样的消息仍然存在。
在我控制我自己也尝试:
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(page.clientScript);
return new ContentResult
{
ContentType = "text/xml", // also tried text/html
Content = Encoding.UTF8.GetString(bytes),
ContentEncoding = System.Text.Encoding.UTF8
};
同样的问题。
- 更新 -
这是我如何调用MVC应用程序返回文本:
// used to load scripts on to the client script using a non-blocking asynch request
(function() {
function async_load(){
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://myserver/MyAppPath/someids';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent)
window.attachEvent('onload', async_load);
else
window.addEventListener('load', async_load, false);
})();
2012-04-23
ElHaix