我正在尝试将提交按钮发送到php文件,然后给出一个弹出通知已完成。目前,当我运行以下内容时,它只是给我通知,但没有发布任何信息。然后它重定向到一个空的search.php,没有帖子数据。我需要它来简单地给出弹出窗口,提交信息,并保持在同一页面上。我似乎无法弄清楚我的表格有什么问题
HTML:
<div class="panel-body">
<div class="row">
<form class="request" action="search.php" method="POST">
<div class="col-lg-12">
<form role="form">
<div class="form-group">
<p>WO notations appear at the top of the work order screen. Only submit useful information that can be provided to builders/centerpoint. Other importation information may include bricks, scaffles, dogs, or home owners preventing installation. Be sure to include phone numbers if available.</p>
<label>Information</label>
<div><input class="form-control" placeholder="Enter information here" type="text" name="Comment[]"></div>
</div>
<button type="submit" name="notation" class="btn btn-default" onClick="AddNotation(<?php echo $orow['WorkOrder']; ?>);">Submit Button</button>
<button type="reset" class="btn btn-default">Reset Button</button>
</form>
</div>
</div>
</div>
的Ajax
<!-- Notation -->
<script>
function AddNotation(wo)
{
jQuery.ajax({
type: "POST",
url: "functions/woNotation.php",
data: 'wo='+wo,
cache: false,
success: function(response)
{
alert("Your notation has been added to this work order");
}
});
}
</script>
PHP(woNotation.php)
<?php
include("../../db.php");
$woid = $_POST['wo'];
$date = date('m-d-Y');
$notationsql = "INSERT INTO Comments (WorkOrder, Comment, Priority, Date) VALUES ('".$woid."', '".$_POST['Comment']."', '1', '".$date"')";
mysql_query($notationsql) or die(mysql_error());
?>
答案 0 :(得分:0)
您应该将数据更改为以下内容:
data: {wo: wo}
答案 1 :(得分:0)
HTML CODE
<form name="exampleform">
<input class="form-control" placeholder="Enter information here" type="text" name="Comment[]">
<input type="hidden" name="woData" value="<?php echo $orow['WorkOrder']; ?>">
</form>
在你的javascript文件中。
jQuery('form[name="exampleform"]').submit(function(e){
e.preventDefault();
var formData = $(this).serialize();
jQuery.ajax({
type: "POST",
url: "functions/woNotation.php",
data: formData,
cache: false,
success: function(response)
{
if (response === "SUCCESS") {
alert("Your notation has been added to this work order");
}
else {
//do something
}
}
});
});
PHP woNotation.php
<?php
include("../../db.php");
$woid = $_POST['woData'];
$date = date('m-d-Y');
$notationsql = "INSERT INTO Comments (WorkOrder, Comment, Priority, Date) VALUES ('".$woid."', '".$_POST['Comment']."', '1', '".$date"')";
$data = mysql_query($notationsql) ? "SUCCESS" : "FAILURE";
echo $data;
?>
如果出现刺痛,您还可以检查console.log(响应)&#34; FAILURE&#34;在你的日志中,这意味着你的db.php文件存在问题,因为mysql_query无效。
答案 2 :(得分:0)
<div class="panel-body">
<div class="row">
<form class="request" action="search.php" method="POST">
<div class="col-lg-12">
<form role="form">
<div class="form-group">
<p>WO notations appear at the top of the work order screen. Only submit useful information that
can be provided to builders/centerpoint. Other importation information may include bricks,
scaffles, dogs, or home owners preventing installation. Be sure to include phone numbers if
available.</p>
<label>Information</label>
<div><input class="form-control" placeholder="Enter information here" type="text"
name="Comment[]"></div>
</div>
<button type="submit" name="notation" class="btn btn-default"
onClick="return AddNotation(<?php echo $orow['WorkOrder']; ?>);">Submit Button
</button>
<button type="reset" class="btn btn-default">Reset Button</button>
</form>
</div>
</div>
</div>
<script>
function AddNotation(wo) {
jQuery.ajax({
type: "POST",
url: "functions/woNotation.php",
data: {'wo': wo},
cache: false,
success: function (response) {
alert("Your notation has been added to this work order");
}
});
}
</script>