我一直在使用 AJAX、JQuery 和 Sessions 很长一段时间。但这是我第一次遇到这个问题。
我正在向另一个页面发送正常的发布请求,并且像我的旧代码一样,我使用目标页面中的会话来测试我的 AJAX 请求是否成功。
在我所做的所有这些时间里,它都运行良好,当然,除非有一些明显的 Javascript 错误阻止我的 AJAX 成功进行。
现在发生的情况是,要使 ajax 请求成功,我需要在关闭并重新打开浏览器后触发它,如果我在发送第一个请求后再次执行它,它将不再成功,另一个有趣的事情是当我启用 AJAX 的错误响应时,我总是会收到一个错误,这真的很烦人,因为我无法确定这个问题的根本原因。
这是服务器问题或代码问题还是我不知道的某些规则?
我的代码不包括包含的 JS:
<style type="text/css">
.input-select { width: 200px; }
.bordered-table { border-collapse:collapse; margin:5px; }
.bordered-table td { border:1px solid #ccc; padding:4px; }
</style>
<link href="/admin/shop/css/tabs.css" type="text/css" rel="stylesheet" media="screen" />
<link href='http://fonts.googleapis.com/css?family=Raleway:400,500,700,800' rel='stylesheet' type='text/css'>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
$(".tab_content").hide();
$("ul.tabs").each(function () {
$(this).find('li:first').addClass("current");
$(this).next('.panes').find('.tab_content:first').show();
});
/* binding click to display another tab */
$("ul.tabs li a").click(function(event) {
var cTab = $(this).closest('li');
cTab.siblings('li').removeClass("current");
cTab.addClass("current");
cTab.closest('ul.tabs').nextAll('.panes:first').find('.tab_content').hide();
var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
function checkIt(evt) {
evt = (evt) ? evt : window.event
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
status = "This field accepts numbers only."
return false
}
status = ""
return true
}
function addRows(elem) {
var ctr = parseInt($("#rows_ctr").val())+parseInt(1);
var row = $(elem);
emails_dropdown = $("#email_id_sample").clone();
row.closest('.adder').parents(".adder-row").before('<tr><td><b>Subject</b>:</td><td><select name="email_id[]" id="email_id_'+ctr+'" style="width: 350px;margin-right: 5;">'+emails_dropdown.html()+'</select></td></tr>');
$("#rows_ctr").val(ctr);
// $("#email_id_"+ctr).val('');
}
function addForm() {
var ctr = parseInt($("#rows_ctr1").val())+parseInt(1);
form_content = $("#formcopy").clone();
$('#cform > tbody > tr:last').after('<tr><td><div id="crm-feedback'+ctr+'"></div><form id="form'+ctr+'" onsubmit="return setList('+ctr+');">'+form_content.html()+'<form/></td></tr>');
$("#rows_ctr1").val(ctr);
}
function setList(str){
var postDatas = decodeURI($('#form'+str+'').serialize());
console.log('Post data: ' + postDatas);
$.ajax({
url: base_url+"admin/page/file.php",
type: "POST",
cache: false,
data: postDatas,
beforeSend:function(){
$('#crm-feedback'+str+'').html('<center><img src="images/ajax-loader.gif"></center>');
},
success: function(data){
// $('#crm-feedback').html('Saved!').css('color','green');
console.log('Success');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
</script>
<body class="colorbox-body">
<div class="welcome-box">
<h1>Set Group Email and SMS</h1>
</div>
<div class="colorbox-content">
<div id="notification">
<?php
if($email_success){
echo"<font style='color:green;'>Schedule Saved.</font>";
echo '<script>
setTimeout("$(\"#notification\").fadeOut()",5000);
</script>';
}
if($nochanges==1){
echo "<font style='color:red;'>No changes made.</font>";
echo '<script>
setTimeout("$(\"#notification\").fadeOut()",5000);
</script>';
}
?>
</div>
<h2>Set Group Email and SMS</h2>
<table id="cform">
<tr>
<td>
<form id = "form0" name="form0" onsubmit="return setList(0);">
<div class="sel">
<?php
$ctr = 0;
//get group emails
$sql_grpemails = "some things";
$res_grpemails = mysql_query($sql_grpemails);
if(mysql_num_rows($res_grpemails) > 0) {
while($row_grpemails = mysql_fetch_assoc($res_grpemails)) {
echo '<tr><td><b>Subject:</b></td>';
echo '<td><select name="email_id[]" id="email_id_'.$ctr.'" style="width: 350px;margin-right: 5;">
<optgroup label="Emails">
<option value="">-- Select --</option>';
$res_savedemails = mysql_query($sql_savedemails);
while($row_savedemails = mysql_fetch_assoc($res_savedemails)) {
echo '<option value="'.$row_savedemails['sam_msg_id'].'" '.($row_savedemails['sam_msg_id']==$row_grpemails['email_id']?'selected':'').'>'.$row_savedemails['sam_subject'].'(Email)</option>';
}
echo '
</optgroup>
<optgroup label="SMS">';
$res_savedsms = mysql_query($sql_savedsms);
while($row_savedsms = mysql_fetch_assoc($res_savedsms)) {
echo '<option value="'.$row_savedsms['id'].'-sms" '.($row_savedsms['id']==$row_grpemails['email_id']?'selected':'').'>'.$row_savedsms['subject'].'(SMS)</option>';
}
echo '
</optgroup>
</select></td></tr>';
$ctr++;
}
}
?>
<table cellpadding="3">
<tr>
<td>
<b>Subject:</b>
</td>
<td>
<select name="email_id[]" id="email_id_<?php echo $ctr;?>" style="width: 350px;margin-right: 5;">
<optgroup label="Emails">
<option value="">-- Select --</option>
<?php
$res_savedemails = mysql_query($sql_savedemails);
while($row_savedemails = mysql_fetch_assoc($res_savedemails)) {
echo '<option value="'.$row_savedemails['sam_msg_id'].'">'.$row_savedemails['sam_subject'].'</option>';
}
?>
</optgroup>
<optgroup label="SMS">
<?php
$res_savedsms = mysql_query($sql_savedsms);
while($row_savedsms = mysql_fetch_assoc($res_savedsms)) {
echo '<option value="'.$row_savedsms['id'].'-sms">'.$row_savedsms['subject'].'</option>';
}
?>
</optgroup>
</select>
</td>
</tr>
<tr class="adder-row">
<td colspan="2">
<input type="button" class="adder btn-link right" value="Add More" onclick="addRows(this);" />
</td>
</tr>
</table>
</div>
<br/>
<input type="hidden" name="rows_ctr" id="rows_ctr" value="<?php echo $ctr;?>" />
<input type="hidden" name="rows_ctr1" id="rows_ctr1" value="<?php echo $ctr;?>" />
<input type="hidden" name="gid" id="" value="<?php echo $_GET['gid'];?>" />
<input type="submit" value="Save" class="btn-link right" />
<div class="clr"></div>
</div>
</form>
</td>
</tr>
</table>
<table width="95%">
<tr>
<td colspan="2">
<input type="button" class="btn-link right" value="Add More" onclick="javascript:addForm();" />
</td>
</tr>
</table>
<select name="email_id_sample" id="email_id_sample" style="display:none;">
<optgroup label="Emails">
<option value="">-- Select --</option>
<?php
$res_savedemails = mysql_query($sql_savedemails);
while($row_savedemails = mysql_fetch_assoc($res_savedemails)) {
echo '<option value="'.$row_savedemails['sam_msg_id'].'">'.$row_savedemails['sam_subject'].'</option>';
}
?>
</optgroup>
<optgroup label="SMS">
<?php
$res_savedsms = mysql_query($sql_savedsms);
while($row_savedsms = mysql_fetch_assoc($res_savedsms)) {
echo '<option value="'.$row_savedsms['id'].'-sms">'.$row_savedsms['subject'].'</option>';
}
?>
</optgroup>
</select>
<form id = "formcopy" name="form1" method="post" action="" style="display:none">
<table cellpadding="3">
<tr>
<td>
<b>Subject:</b>
</td>
<td>
<select name="email_id[]" id="email_id_<?php echo $ctr;?>" style="width: 350px;margin-right: 5;">
<optgroup label="Emails">
<option value="">-- Select --</option>
<?php
$res_savedemails = mysql_query($sql_savedemails);
while($row_savedemails = mysql_fetch_assoc($res_savedemails)) {
echo '<option value="'.$row_savedemails['sam_msg_id'].'">'.$row_savedemails['sam_subject'].'</option>';
}
?>
</optgroup>
<optgroup label="SMS">
<?php
$res_savedsms = mysql_query($sql_savedsms);
while($row_savedsms = mysql_fetch_assoc($res_savedsms)) {
echo '<option value="'.$row_savedsms['id'].'-sms">'.$row_savedsms['subject'].'</option>';
}
?>
</optgroup>
</select>
</td>
</tr>
<tr class="adder-row">
<td colspan="2">
<input type="button" class="adder btn-link right" value="Add More" onclick="addRows(this);" />
</td>
</tr>
</table>
<div class="scheduled_days">
<p><b>Scheduled (Days)</b></p>
<br/>
<ul class="tabs">
<li><a href="#tab5">Days</a></li>
<li><a href="#tab6">Weekly</a></li>
<li><a href="#tab7">Monthly</a></li>
<li><a href="#tab8">Yearly</a></li>
</ul>
<div class="panes">
<div id="tab5" class="tab_content" style = "padding-top: 20px;">
<b>Recurring:</b> Every <input type="text" name="dval"/> Day(s)
<br/>
<small>*Reference date: Member date added to the group</small>
</div>
<div id="tab6" class="tab_content" style = "padding-top: 20px;">
<b>Recurring:</b> Every <input type="text" name="wval"/> Week(s)
<br/>
<small>*Reference date: Member date added to the group</small>
<br/>
<input type="radio" name="recursched" value="weekmon"/> Monday <input type="radio" name="recursched" value="weektue"/>Tuesday <input type="radio" name="recursched" value="weekwed"/>Wednesday <input type="radio" name="recursched" value="weekthu"/>Thursday <input type="radio" name="recursched" value="weekfri"/> Friday
<input type="radio" name="recursched" value="weeksat"/> Saturday <input type="radio" name="recursched" value="weeksun"/> Sunday
</div>
<div id="tab7" class="tab_content" style = "padding-top: 20px;">
<b>Recurring:</b> <br/><small>*Reference date: Member date added to the group</small>
<br/>
<input type="radio" name="recursched" value="monthlyrecur"/> Day <input type="text" name="mday"/> of every <input type="text" name="mmonth"/> month(s)
<br/>
<input type="radio"name="recursched" value="monthlyrecur"/> The
<select name="mweek" class="styled">
<option value="First">First</option>
<option value="Second">Second</option>
<option value="Third">Third</option>
<option value="Fourth">Fourth</option>
</select>
</div>
<div id="tab8" class="tab_content" style = "padding-top: 20px;">
<b>Recurring:</b> <br/><small>*Reference date: Member date added to the group</small>
<br/>
<input type="radio" name="recursched" value="yearlyrecur"/> Every
<select name="ymonth" class="styled">
<?php
$ymontshar = array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
for($ymonths=0;$ymonths<12;$ymonths++){
?>
<option value="<?php echo $ymontshar[$ymonths]; ?>"><?php echo $ymontshar[$ymonths]; ?></option>
<?php
}
?>
</select>
<input type="text" name="yday"/>
<br/>
<input type="radio" name="recursched" value="yearlyrecur2"/> The
<select name="yweek" class="styled">
<option value="first">First</option>
<option value="second">Second</option>
<option value="third">Third</option>
<option value="fourth">Fourth</option>
</select>
<select name="yday" class="styled">
<option value="monday">Monday</option>
<option value="tuesday">Tuesday</option>
<option value="wednesday">Wednesday</option>
<option value="thursday">Thursday</option>
<option value="friday">Friday</option>
<option value="saturday">Saturday</option>
<option value="sunday">Sunday</option>
</select>
of
<select name="ymonth2" class="styled">
<?php
for($ymonths2=0;$ymonths2<12;$ymonths2++){
?>
<option value="<?php echo $ymontshar[$ymonths2]; ?>"><?php echo $ymontshar[$ymonths2]; ?></option>
<?php
}
?>
</select>
</div>
</div>
<br/>
<input type="hidden" name="rows_ctr" id="rows_ctr" value="<?php echo $ctr;?>" />
<input type="hidden" name="rows_ctr1" id="rows_ctr1" value="<?php echo $ctr;?>" />
<input type="hidden" name="gid" id="" value="<?php echo $_GET['gid'];?>" />
<input type="submit" value="Save" class="btn-link right" />
<div class="clr"></div>
</div>
</form>
<br />
<div class="warning-msg">
<b>*Please note that changing the schedule may result in some members not receiving emails.</b>
</div>
</div>
</body>
它现在可以在 chrome 上运行,但并非在所有情况下,我可能需要提交两次才能通过它