脚本在实际服务器中不起作用,但在 localhost XAMPP 中起作用
Posted
技术标签:
【中文标题】脚本在实际服务器中不起作用,但在 localhost XAMPP 中起作用【英文标题】:Script not working in actual server but works in localhost XAMPP 【发布时间】:2016-11-19 15:30:33 【问题描述】:我似乎找不到问题,因为我的代码在 localhost xampp 中工作。但是一旦我上传到实际的服务器它就不起作用了。
没有任何错误输出
当我提交表单时,它会输出加载程序,然后消失,<div id="status"></div>
没有输出成功消息或错误消息
<script>
function _(id) return document.getElementById(id);
function submitForm()
_("bankbtn").disabled = true;
_("status").innerhtml = '<div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"><span class="sr-only">Loading...</span></div></div><br />';
var formdata = new FormData();
formdata.append( "bcountry", _("bcountry").value );
formdata.append( "bname", _("bname").value );
formdata.append( "baname", _("baname").value );
formdata.append( "bno", _("bno").value );
formdata.append( "bswift", _("bswift").value );
var ajax = new XMLHttpRequest();
ajax.open( "POST", "editbank_engine.php" );
ajax.onreadystatechange = function()
if(ajax.readyState == 4 && ajax.status == 200)
if(ajax.responseText == "success")
_("editbank").innerHTML = '<div class="alert alert-success"><h2>Changes has been saved</h2></div>';
else
_("status").innerHTML = ajax.responseText;
_("bankbtn").disabled = false;
ajax.send( formdata );
</script>
html
<div class="modal fade" id="edit" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
<form id="editbank" onsubmit="submitForm(); return false;">
<div id="status"></div>
<input class="form-control" type="text" value="<?php echo $bank['bank_country']?>" id="bcountry" placeholder="Bank Country" required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_name']?>" id="bname" placeholder="Bank Name" required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_accountname']?>" id="baname" placeholder="Bank Account Name" required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_no']?>" id="bno" placeholder="Bank Account No." required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_swiftcode']?>" id="bswift" placeholder="Bank Swift Code"/><br />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="bankbtn" type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
php
<?php
session_start();
include_once('../php/config.php');
include_once('../php/func.php');
if(
isset($_SESSION['hotel_id']) &&
isset($_POST['bcountry']) &&
isset($_POST['bname']) &&
isset($_POST['baname']) &&
isset($_POST['bno']) &&
isset($_POST['bswift']) &&
!empty($_SESSION['hotel_id']) &&
!empty($_POST['bcountry']) &&
!empty($_POST['bname']) &&
!empty($_POST['baname']) &&
!empty($_POST['bno']) &&
!empty($_POST['bswift'])
)
$update = $dbo->prepare('UPDATE bank_details SET bank_country=:bankcountry, bank_name=:bankname, bank_accountname=:bankaccountname, bank_no=:bankno, bank_swiftcode=:bankswift, active=0, last_updated=NOW() WHERE hid=:hid AND active = 1');
$update->bindParam(':bankcountry', $_POST['bcountry'], PDO::PARAM_STR);
$update->bindParam(':bankname', $_POST['bname'], PDO::PARAM_STR);
$update->bindParam(':bankaccountname', $_POST['baname'], PDO::PARAM_STR);
$update->bindParam(':bankno', $_POST['bno'], PDO::PARAM_STR);
$update->bindParam(':bankswift', $_POST['bswift'], PDO::PARAM_STR);
//$update->bindParam(':active', '0', PDO::PARAM_STR);
$update->bindParam(':hid', $_SESSION['hotel_id'], PDO::PARAM_STR);
$update->execute();
if($update->rowCount() == 1)
echo 'success';
//echo '<div class="alert alert-success"><b>Changes has been saved</b></div>' ;
//mail_log('-User '.$_SESSION['extranet_user'].' has updated his bank details at '.date(time(), 'Y/m/d H:i:s').'');
else
echo '<div class="alert alert_danger"><strong>Error has occurred, You can only update once your account has been approved</strong></div>';
//mail_log(' User '.$_SESSION['extranet_user'].' has run into an error via bank details at '.date(time(), 'Y/m/d H:i:s').'');
?>
【问题讨论】:
错误报告可能在生产主机上被抑制。在 PHP 代码的开头插入error_reporting(E_ALL);
以查看可能的错误消息。
【参考方案1】:
所以我发现了问题。它在我的 phpmyadmin (实际服务器)
我正在使用具有id of 0
的测试用户测试我的表单,我所要做的就是将其更改为 1,由于某种原因它不能设置为 0,否则它将无法工作
【讨论】:
以上是关于脚本在实际服务器中不起作用,但在 localhost XAMPP 中起作用的主要内容,如果未能解决你的问题,请参考以下文章
串行 AT 命令在 python 脚本中不起作用,但在 Minicom 中起作用
ajax 跨源请求在 safari 中不起作用,但在 chrome 和 firefox 中起作用
模态在我的网络服务器中不起作用,但在 localhost 中起作用。这是为啥?