我有一个脚本必须执行以下操作。在插入一些数据后,它必须显示一条消息“成功插入”。它不起作用,但是我不知道为什么我对Jquery缺乏经验。我有3个文件。
脚本文件:
$(document).on("click", ".btnAddSubcat", function(e) {
event.preventDefault();
var subcatvalue = $('.subCat').val();
var subcatprocedure = $('.subProcedure').val();
var url = "../service/functions/postActions.php";
swal({
title: 'Add a new sub-category?',
text: "Are you sure to Add this sub-category?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Add it!'
}).then(function () {
$.ajax({
type: 'POST',
url : url,
data: {'subCat': subcatvalue, 'Procedure': subcatprocedure},
success: function (data) {
swal({
title: 'Add!',
text: "You Add a sub-category!",
type: 'success',
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK'
}).then(function () {
window.location.reload();
})
}
});
})
});
PHP文件
<div class="form-group">
<label for="inputsubcat" class="col-sm-2 control-label">SubCategory:</label>
<div class="col-sm-10">
<input type="text" class="form-control subCat" name="subCat" placeholder="...">
</div>
</div>
<div class="form-group">
<label for="inputprocedure" class="col-sm-2 control-label">Procedure:</label>
<div class="col-sm-10">
<textarea name="Procedure" rows="8" cols="30" style=" resize: none;" class="form-control subProcedure" placeholder="..."></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Video:</label>
<div class="col-md-10">
<input type="file" name="HWVideo" id="HW-Video" class="form-control uploadVideo" required="true" accept="video/mp4">
<video width="450" controls>
<source src="mov_bbb.mp4" id="videoLink">
Your browser does not support HTML5 video.
</video>
</div>
</div>
<div class='form-group'>
<div class='col-sm-offset-2 col-sm-10'>
<input type='hidden' name='Subcatadd' />
<button class='btnAddSubcat btn btn-success glyphicon glyphicon-floppy-disk' type='submit'></button>
</div>
</div>
</form>
功能文件
function AddSubCat() {
$Catid = $_POST['cat-select'];
$Subnaam = $_POST['subCat'];
$procedure = $_POST['Procedure'];
和一些插入的东西。可以,但不会显示该消息。我感谢您的帮助!一定是这样
答案 0 :(得分:1)
我发现了
$Catid = $_POST['cat-select'];
在AJAX请求中,没有名为cat-select的参数。 此外,在使用它们之前,应检查$ _POST和$ _GET是否确实存在。
答案 1 :(得分:1)
嗨,它可能是特定于浏览器的。选择铬。如果是在本地环境中,则应避免在如下所示的脚本CDN上使用Https://。