<script>
$(document).ready(function() {
$("#btnSubmit").live('click',function(){
var sum = '0';
$("[id^=FormData_][id$=_c_data]").each(function(){
var c_data = $(this).val();
var required = $(this).attr("data-required");
var label = $(this).attr("data-label");
if(required == '1'){
if(c_data == ""){
sum += '1';
}
}
});
if(sum == "0"){
$("[id^=FormData_][id$=_c_data]").each(function(){
var c_data = $(this).val();
var admin = $(this).attr("data-admin");
var form = $(this).attr("data-form");
var component = $(this).attr("date-component");
var unic = $(this).attr("data-unic");
var user = $(this).attr("data-user");
var url = "<?php echo Yii::app()->createUrl('formdata/admin&id='.$form_id);?>";
if(c_data == ""){
var site_url = "<?php echo Yii::app()->createUrl('/formdata/deleteDetail' ); ?>";
jQuery.ajax({
type: "POST",
url: site_url,
data: {new_value:c_data,admin:admin,form:form,component:component,unic:unic,user:user},
cache: false,
async: false,
success: function(response){
}
});
} else {
var site_url = "<?php echo Yii::app()->createUrl('/formdata/updateDetailValue' ); ?>";
jQuery.ajax({
type: "POST",
url: site_url,
data: {new_value:c_data,admin:admin,form:form,component:component,unic:unic,user:user},
cache: false,
async: false,
success: function(response){
}
});
}
});
window.location = "http://www.example.com";
}else {
if(sum != ""){
bootbox.dialog({
message: 'Please Fill All Required Field !',
title: 'Alert',
buttons: {
main: {
label: 'OK',
className: 'blue'
}
}
});
return false;
}
}
});
});
</script>
此脚本中的% window.location = "http://www.example.com"
;不起作用。但我检查了警报消息,它工作正常。为什么它不能在if条件下工作。我需要重定向页面时,每个功能都完成了。请任何人帮助我:-())())()
发布于 2017-04-19 05:22:35
试试这个。,
window.location.href = 'http://www.google.com';
这可能对你有用。
Window.location.href and Window.open () methods in JavaScript
发布于 2017-04-19 05:31:17
jQuery不是必需的,window.location.replace(url)
将最好地模拟HTTP重定向。
尽管如此,您仍然希望使用此$(location).attr('href', 'url')
对jQuery执行此操作
发布于 2017-04-19 06:00:23
如果我没弄错您的问题,那么您希望在each
函数内的所有ajax
请求完成后重定向用户。为此,您可以创建一个array
来保存每个ajax
请求的成功状态,并根据此array
执行重定向任务。
将以下几个代码片段添加到现有代码中:
#btnSubmit
click
函数中(不过,我建议您使用.on()
委派方法)var ajax_succ_arr = [];//成功状态容器var this_ajax_succ = false;//在两个ajax
调用的success
函数中(在each
函数中)标记
如果(c_data == ""){ ...jQuery.ajax({ ...成功: function( response ){ if(response == "1"){ this_ajax_succ = true;//收到需要的响应设置为true } });ajax_succ_arr.push(this_ajax_succ);//推送到成功数组}否则{ ...jQuery.ajax({ ...成功: function( response ){ if(response == "1"){ this_ajax_succ = true;//如果收到需要的响应});ajax_succ_arr.push(this_ajax_succ);//推送到成功数组}
each
函数结束之后。if(ajax_succ_arr.indexOf(false)<0){ // if所有状态都正常“http://www.example.com";}
希望这能有所帮助。
https://stackoverflow.com/questions/43486679
复制