我想要的是:
这是我的按钮代码:
@Override
protected void onInitialize() {
add(createOkLink());
}
private IndicatingAjaxLink<Void> createOkLink() {
final IndicatingAjaxLink<Void> ret = new IndicatingAjaxLink<Void>("okLink") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
//when I click on it, this button (link) should not be enabled while the rest of the methods are not finished.
method1(); //about 2-5 seconds running time
method2(); //about 2-5 seconds running time
method3(); //about 2-5 seconds running time
feedback.success("success");
target.add(feedback);
//after every method has finished, …Run Code Online (Sandbox Code Playgroud) 我们正在整个应用程序中使用Ajax调用 - 尝试在尝试执行任何Ajax请求时,如果会话已经过期,则尝试找到重定向到登录页面的全局解决方案.我编写了以下解决方案,从这篇文章中获取帮助 - 在ajax调用中处理会话超时
不确定为什么在我关心的事件中"HandleUnauthorizedRequest"没有被解雇.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CheckSessionExpireAttribute :AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
var url = new UrlHelper(filterContext.RequestContext);
var loginUrl = url.Content("/Default.aspx");
filterContext.HttpContext.Session.RemoveAll();
filterContext.HttpContext.Response.StatusCode = 403;
filterContext.HttpContext.Response.Redirect(loginUrl, false);
filterContext.Result = new EmptyResult();
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器操作中使用Above自定义属性如下:
[NoCache]
[CheckSessionExpire]
public ActionResult GetSomething()
{
}
Run Code Online (Sandbox Code Playgroud)
AJAX Call(JS部分):
function GetSomething()
{
$.ajax({
cache: false,
type: "GET",
async: true,
url: "/Customer/GetSomething",
success: function (data) {
},
error: function (xhr, …Run Code Online (Sandbox Code Playgroud) 在经历了几次理解问题之后,我遇到了非常困难的问题.我无法让我的自定义标头处理来自AngularJS的$ request.我的定义如下:
$scope.re = $resource('/', {
callback: 'JSON_CALLBACK'
}, {
'updateCart': {
method: 'POST',
headers: {
'module': 'Shop',
'mod_id': '1',
'event': 'updateCart'
}
}
});
Run Code Online (Sandbox Code Playgroud)
还在这里JSFIDDLE
这个问题仍然有效吗?还有另一种设置自定义标头的方法吗?谢谢你的帮助!:)
我遵循HTML代码:
<form action="view_rebate_master.php" method="post">
<div class="form-group">
<label for="company_name" class="col-lg-12">Manufacturer</label>
<div class="col-lg-12">
<select id="company_id" class="form-control" onchange="GetProductByManufacturerID(this.value)" name="company_id">
<option selected="selected" value="">All Manufacturers</option>
<option value="40">Test</option>
<option value="42">RK</option>
<option value="49">Blue Nun</option>
<option value="58">Unique Imports</option>
<option value="59">Pernod Ricard</option>
<option value="77">Smoking Loon</option>
<option value="78">Beringer</option>
</select>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<label for="product_id" class="col-lg-12">Product Name</label>
<div class="col-lg-12">
<select id="product_id" class="form-control" name="product_id">
<option selected="selected" value="">All Products</option>
<option value="12">Riesling</option>
<option value="24">Superio Vodka</option>
<option value="32">Heineken</option>
<option value="33">Strong Bow</option>
<option value="34">Grocery</option>
<option value="35">Ruler</option>
<option value="36">Glass</option>
<option value="37">Brown Bread</option>
<option value="38">White …Run Code Online (Sandbox Code Playgroud) 嗨,我有一个登录系统的jQuery ajax请求.起初,它运作良好.但经过几次尝试后,它才刚刚开始出现负面反应.我检查了萤火虫,它说响应是,在我的情况下"连接".但是ajax响应只显示"Not_connected".我不知道该怎么办:(请帮帮我.
这是我的jquery代码:
var data_str = "username="+usrn+"&password="+pwd;
$.ajax({
type: "POST",
url: "index.php?rnd=" + Math.random(),
data : data_str,
complete : function(xhr,data){
if(data == 'connected'){window.location.href = 'admin.php';}
else if(data = 'not_connected'){ error_gen.html('Invalid username or password'); }
alert(data);
}
});
Run Code Online (Sandbox Code Playgroud)
AS代码为PHP代码:
$log_result = $u_obj->login_user();
if($log_result == true)/*user is connected*/
{
echo 'connected';
exit;/*stoping the script after sending the result*/
}
elseif($log_result == false)/*error while logging in*/
{
echo 'not_connected';
exit;/*stoping the script after sending the result*/
}
Run Code Online (Sandbox Code Playgroud) 当我的webView访问网址时捕获http包时遇到了问题.该软件包显示ajax发送的请求在标头中有一个"X-requested-with"键,其中包含我的应用包名称的值,如'com.xxx'.我不希望我访问过的网址知道我的应用程序发出的请求,所以我需要将"X-requested-with"键替换为另一个值.但我尝试将自定义标头添加到WebView资源请求中 - android,所有这些都不起作用.
loadUrl(Strring url, Map<String, String> extraHeaders)将仅在页面请求中调用,而不是在ajax发送的资源请求中调用.shouldOverrideUrlLoading(WebView view, String url)并将WebViewClient.shouldInterceptRequest(android.webkit.WebView view, java.lang.String url)在每个请求中调用,但我无法修改其中的标头.那么问题的任何解决方案呢?非常感谢.
我正在使用ajax加载器(如请等待.gif图像)图像进行ajax调用.在某些日子之前,它完美地工作并以铬合金显示.
我没有看到图像有任何问题,或者我们没有改变它.它在IE,Mozilla和其他浏览器中正确显示,但我不知道为什么它没有在chrome中显示.
我曾经看过谷歌浏览器中没有显示Ajax Loader但没有得到任何帮助.
html标记是
<div id="divajaxProgress" class="progressouter" style="display: none;">
<div class="ProgressInner">
<img alt="" title="Please wait..." src="../Images/ajax-loader.gif" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
divajaxProgress将在ajax调用出现时显示,一个简单的例子是页面加载.这是功能
function HideProgress() {
$("#divajaxProgress").hide();
}
function ShowProgress() {
if ($('#divajaxProgress').is(':visible') == false) {
$("#divajaxProgress").show();
}
}
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到图像
请告诉我这里有什么问题.
我有一种我无法理解的怪异行为.这是代码:
$.ajax({
url: ...,
dataType: ...,
data: ...,
success: function( data ) {
...
for (var i=0; i<data.length; i++) {
label_to_change = "some-" + i + "-item"
$.ajax({
url: ...,
dataType: ...,
data: ...,
success: function( data ) {
// Why I can't access the value in each loop, this will give me allways the last loop value
console.log(label_to_change)
}
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
我需要在第二个ajax请求中访问var label_to_change,但不是这样:
some-0-item
some-1-item
some-2-item
Run Code Online (Sandbox Code Playgroud)
我懂了:
some-2-item
some-2-item
some-2-item
Run Code Online (Sandbox Code Playgroud)
关于我做错的任何线索?
最好的祝福,
就像标题所说,我想中止之前的ajax请求.每当用户键入请求数据的字母(或数字)时,组合框请求通过ajax,就像我通过ajax说的那样,然后将数据返回到组合框.
我的问题是每当我在字段中输入用户输入时,ajax请求就会堆积起来.
我想要做的是先中止先前的请求然后继续当前的请求.我试过这段代码:
comboObj.onTypeAhead = Ext.Function.createInterceptor(comboObj.onTypeAhead, function() {
Ext.Ajax.abort(); //aborts the last Ajax request
return true; //runs the onTypeAhead function
});
Run Code Online (Sandbox Code Playgroud)
那没用,然后尝试了这个:
......
listeners: {
beforequery: function(evt){
Ext.Ajax.abortAll(); //cancel any previous requests
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
这对我来说不起作用,因为我有一个也使用ajax请求的计时器,如果执行了监听器,它也将被取消.
我该怎么做呢?
我不知道我的头衔是否有点误导.但这是我真正需要帮助的.
我正在搞这个网址:
$.get("/fb/login/"+fbEmail, function(data){
console.log(data);
});
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
GET /fb/login/:email presentation.controllers.Auth.authenticateSocialNetwork(email:String)
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
def authenticateSocialNetwork(email:String) = Action {
if(!editorRepo.getEditorByEmail(email).isEmpty){
Redirect(routes.Profile.editorProfile).withSession(Security.username -> email)
} else {
Redirect(routes.Profile.initiatorProfile).withSession(Security.username -> email)
}
}
Run Code Online (Sandbox Code Playgroud)
我对此的期望是我的行动被召唤并触发其中的内容.换句话说,重定向.
但实际发生的事情,不是那么不合逻辑,就是我的$ .get调用得到了我的重定向响应.
如何在不发送对javascript的响应的情况下实际调用我的action-method?
这是我在javascript中的功能,在上面的评论中我们的讨论中更清楚地发布了这个片段.
function addClickToLoginButtons(){
$("#loginWithFb").click(function(){
FB.login(function(response){
if(response.authResponse){
FB.api('/me', function(response){
var fbEmail = response.email;
$.get("/fb/isRegisteredAtNetwork/"+fbEmail+"/facebook", function(data){
if(data == "true"){
if(confirm("Do you want to log with facebook-account "+fbEmail+"?")){
$.get("/fb/login/"+fbEmail, function(data){ *//HERE'S WHERE I WOULD WANT TO CALL MY METHOD IN SCALA*
console.log(data);
});
} else …Run Code Online (Sandbox Code Playgroud) 我想通过反应项目中的axios从服务器获取一些数据.当我把网址放在浏览器上并点击进入浏览器时问我用户名和密码,之后,我可以看到json数据.但我不知道如何在get方法中设置axios头中的密码和用户名.我在很多论坛和网页上搜索过它,特别是这个链接对我没有帮助:发送axios获取带有授权标题的请求.所以最后我尝试了(在此之前很多事情,但我更困惑):
componentDidMount() {
axios.get('http://my_url/api/stb', {auth: {
username: 'usrnm',
password: 'pswrd'
}})
.then(function(response) {
console.log(response.data);
console.log(response.headers['Authorization']);
}).catch(err => console.log(err));
}
Run Code Online (Sandbox Code Playgroud)
而我什么都得不到.我在控制台中收到此错误:
Error: Network Error
Stack trace:
createError@http://localhost:3000/static/js/bundle.js:2195:15
handleError@http://localhost:3000/static/js/bundle.js:1724:14
Run Code Online (Sandbox Code Playgroud)
实际上,api文档提到了这些话:
如果没有标题或数据不正确 - 服务器的答案将包含HTTP状态401 Unauthorized和消息:
< {"status":"ERROR","results":"","error":"401 Unauthorized request"}
Run Code Online (Sandbox Code Playgroud)
要成功验证,只需在API的每个请求标头中添加:
Authorization: Basic <base64encode("login":"password")>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我使用邮递员时,响应会在身体部分下方向我发送"401未经授权"的回复.但我在浏览器的控制台中看不到任何401错误.