我有一个使用Forms Authentication在asp.net mvc中编写的后端服务器.未对用户进行身份验证时,服务器将自动将302重定向发送到"登录"操作并返回"登录"页面.
在客户端,我有一个项目列表.此列表仅供经过身份验证的用户访问.在页面上,我有一个使用Ajax刷新列表的按钮(jQuery的$ .ajax函数).
现在,问题是当身份验证票超时并且用户单击"刷新"按钮时:
我想是当身份验证票证超时和用户点击刷新按钮,我应该能够检测并显示一条消息,询问用户登录.
我尝试通过在Login操作中添加自定义标头(IS_LOGIN)来解决此问题,并在我的ajax响应中检查它.但这不是一个好的解决方案.
所以我的问题是:
谢谢你的回复.
嗨,我试图使用JQuery加载本地JSON文件来显示数据,但我得到一些奇怪的错误.我可以知道如何解决这个问题.
<html>
<head>
<script type="text/javascript" language="javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$.getJSON( "priorities.json" , function( result ){
alert(result.start.count);
});
});
</script></head>
</html>
Run Code Online (Sandbox Code Playgroud)
我只是提醒JSON数据的数量.我的JSON文件位于此html文件所在的目录中,JSON字符串格式如下所示.
{
"start": {
"count": "5",
"title": "start",
"priorities": [
{
"txt": "Work"
},
{
"txt": "Time Sense"
},
{
"txt": "Dicipline"
},
{
"txt": "Confidence"
},
{
"txt": "CrossFunctional"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
JSON文件名的priority.json和错误是
未定义未捕获的Referenceerror优先级
//Create an Angular Module.
var newsModule = angular.module('NewsModule', []);
//Create an Angular Controller.
newsModule.controller('newsCtrl', ['$scope', '$http', function ($scope, $http) {
//function retrives POST,UPDATE,DELETE,GET data
$http.defaults.headers.put = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'
};
$http.defaults.useXDomain = true;
$scope.throughdata = function (){
delete $http.defaults.headers.common['X-Requested-With'];
$http.get('http://www.google.com').then(function(data,error){
alert(data);
alert(error);
$scope.days=data.data;
});
}
}
]);
Run Code Online (Sandbox Code Playgroud)
但我有以下错误
XMLHttpRequest无法加载http://www.google.com/.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许原点'null'访问.
我有一个这样的表(表名:帖子):
+----+--------------------------+-------+------------+
| id | content | type | date |
+----+--------------------------+-------+------------+
| 0 | Some text | TypeA | 2013-04-01 |
| 1 | Some older text | TypeA | 2012-03-01 |
| 2 | Some even older texttext | TypeA | 2011-01-01 |
| 3 | A dog | TypeB | 2013-04-01 |
| 4 | And older dog | TypeB | 2012-03-01 |
| 5 | An even older dog | TypeB | 2011-01-01 |
+----+--------------------------+-------+------------+
Run Code Online (Sandbox Code Playgroud)
使用LINQ表达式我想找到每种类型的最新内容,所以结果应该是 …
我一直在使用一些高级的javascript应用程序,使用大量的ajax请求来呈现我的页面.要使应用程序可以抓取(通过谷歌),我必须关注https://developers.google.com/webmasters/ajax-crawling/?hl=fr.这告诉我们要做的事情:重新设计我们的链接,创建HTML快照,......以使网站可搜索.
我想知道为什么爬虫不运行javascript来获取渲染的页面和索引.这背后有原因吗?或者它是未来可能出现的搜索引擎的缺失特征?
I made a recursive ng-repeat element, and trying to manipulate things has turned into a nightmare, because I don't have reference to the parent I'm iterating over.
The ng-repeat looks like this:
ng-repeat="(key, value) in value"
Run Code Online (Sandbox Code Playgroud)
Remember It's recursive, so each value in value becomes the new value, so I can't just use the "in" value from ng-repeat. I want to do such things as checking if the parent is an array, but $parent is some weird thing, not the …
我有一个ASP.NET MVC页面,其中包含14列的JQuery Editable Datatable.我有一个按钮(Apply No Findings)来做客户端计算并且适用于该表中的所有行.
当我们单击此按钮时,在每4行应用计算后,它将显示此"停止运行脚本"消息.
我验证了设置.在"Internet选项"的"高级"选项卡中,"禁用脚本调试(Internet Explorer)"选项已选中.并且"未显示"显示有关脚本错误的通知".
我正在使用Internet Explorer 8.我现在不会在IE9上发生.但这是服务器,我们无法升级到IE9.
我做了研究并尝试了这两个选项,没有任何效果.
例(1): http ://www.codeproject.com/Tips/406739/Preventing-Stop-running-this-script-in-Browsers
示例(2): http ://www.picnet.com.au/blogs/guido/post/2010/03/04/how-to-prevent-stop-running-this-script-message-in-browsers/
任何人都有这个,任何建议都非常感谢.
这是抛出脚本消息的实际代码:
for(i < iTotalRecords;i++)
{
var row = oTableAuditLines.fnGetData(i);
oTableAuditLines.fnUpdate("NF",i,1);
UndoHCPCS(row,i);
UndoHCPCSModCodes(row,i);
UndoLineUnitCount(row,i);
oTableAuditLines.fnUpdate("", i, 6); //Reset Denial Reason Code
UndoNonCoveredCharges(row,i);
CalculateAmountPaidAtLine(row,i);
CalculateEstimatedRecoveryAmountAtLine(row,i);
}
UpdateSummaryLine();
UpdateSummaryLineReasonCode();
Run Code Online (Sandbox Code Playgroud)
通过引用示例(2)中的示例代码,我更改了下面的代码,我仍然收到脚本消息:
//此函数用于避免脚本运行消息
RepeatingOperation = function(op, yieldEveryIteration)
{
var count = 0;
var instance = this;
this.step = function(args)
{
if (++count >= yieldEveryIteration)
{
count = 0;
setTimeout(function() { op(args); }, 1, …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个指令来从验证中排除隐藏的输入元素:http://plnkr.co/edit/Vnwvq2AT7JpgTnoQwGh9?p = preview
app.directive('shownValidation', function() {
return {
require: '^form',
restrict: 'A',
link: function(scope, element, attrs,form) {
var control;
scope.$watch(attrs.ngShow,function(value){
if (!control){
control = form[element.attr("name")];
}
if (value == true){
form.$addControl(control);
}else{
form.$removeControl(control);
}
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
这里的想法是如果元素被隐藏,我将从表单中删除控件,以便它不会影响其他输入有效性.它在我打电话时工作正常 form.$removeControl(control);
,您可以在演示中通过删除名字并单击按钮来隐藏字段来测试它.
但是当我再次单击该按钮时,即使名字无效(空),表单有效性仍然为真
我也尝试添加form.$setValidity(form.$valid && control.$valid)
=>有效状态按预期更新,但是当我输入第一个名称时,有效性仍然是假的.
我的问题是如何解决这个问题?谢谢你的回复.
更新:
感谢@ Michael的回答.这是工作解决方案:
app.directive('shownValidation', function() {
return {
require: '^form',
restrict: 'A',
link: function(scope, element, attrs, form) {
var control;
scope.$watch(attrs.ngShow, function(value) {
if (!control) {
control = …
Run Code Online (Sandbox Code Playgroud) 我们如何使用AngularJs动态地向表单添加文本框元素.例如,在这种情况下,我有一个文本和文本框,我想通过使用AngularJs单击按钮来添加该对的另一个.
<div ng-app>
<div ng-controller="ClickToEditCtrl">
<div ng-hide="editorEnabled" ng-click="editorEnabled=true">
{{title}}
</div>
<div ng-show="editorEnabled">
<input ng-model="title">
<button href="#" ng-click="editorEnabled=false">Done editing</button>
</div>
</div>
</div>
<div>
<input type="text" placeholder="Enter answer">
</div>
Run Code Online (Sandbox Code Playgroud) 我想在我的AngularJS应用程序中有一些事件监听器代码,它将适用于所有控制器的范围.
我基本上想要在某处定义以下内容:
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
function onOnline() {
console.log("just got online event");
$scope.noNetwork = false;
}
function onOffline() {
console.log("just got offline event");
$scope.noNetwork = true;
}
Run Code Online (Sandbox Code Playgroud)
无论哪个控制器范围当前处于活动状态,它都将接收事件.
javascript ×8
angularjs ×5
jquery ×3
ajax ×2
asp.net-mvc ×2
c# ×1
cors ×1
forms ×1
html ×1
http-headers ×1
json ×1
linq ×1
validation ×1