【问题标题】:Insert successfully script not showing插入成功脚本不显示
【发布时间】:2019-04-02 09:43:27
【问题描述】:

我有一个脚本必须执行以下操作。在我插入一些数据后,它必须显示一条带有“插入成功”的消息。它不起作用,但我不知道为什么我对 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'];

还有一些插入的东西。行得通,它只是不会显示消息。我感谢您的帮助!应该是这样的

插入前的图像 插入后

【问题讨论】:

  • 浏览器控制台有什么要说的? 是否请求真的“成功”了(意思是HTTP状态码,去网络面板查看。)
  • 它只是插入数据但它没有显示成功
  • 你为什么要这样做? window.location.reload(); 尝试将其注释掉或使用 setTimeout。使用ajax然后重新加载页面很傻
  • AddSubCat() 函数是干什么用的?
  • @fmsthird 这是我要插入的功能(但我认为其余的不是必需的,因为它插入得很好

标签: javascript php jquery


【解决方案1】:

嗨,它可能是特定于浏览器的。选择镀铬。如果它在本地环境中,您应该避免在脚本 CDN 上使用 HTTPS://,如下所示。

【讨论】:

  • 我在边缘测试过,它可以工作,但在 chrome 中不能工作
  • 您能否分享一下 chrome devTools 控制台的屏幕截图 .. 以便我们为您提供帮助 :)
  • 我添加了截图
  • 试试这个可能对你有帮助...stackoverflow.com/questions/40530598/…
【解决方案2】:

我找到了这个

$Catid = $_POST['cat-select'];

在您的 AJAX 请求中,您没有名为 cat-select 的参数。 此外,您应该在使用之前检查 $_POST 和 $_GET 是否确实存在。

【讨论】:

  • cat-select 是从哪里来的?
  • 来自上方的下拉菜单
猜你喜欢
  • 1970-01-01
  • 2018-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-08
  • 1970-01-01
  • 2017-04-27
相关资源
最近更新 更多