附带的php文件中的jQuery选择器不起作用

问题描述 投票:0回答:1

我做了一个简单的网站来管理和显示项目。对于我的问题,足以知道有3个文件:

  1. [admin-dashboard.php,显示项目和管理功能(减少数量,增加ecc。)]

<?php
	include("includes/header.php");
	include("dbqueries/db-connection.php");
	include("includes/alerts.php");
?>
...
  1. [dashboard-utilities.js包含实现点1的所有JavaScript函数

...
// Reduce quantity button script
function reduceQuantity(item) {
	$.ajax({
	    method: 'get',
	    url: '../dbqueries/reduceQuantity.php',
	    data: {
	        'current_item': item,
	    },
	    success: function() {
	    	//alert("Quantità di " + "\"" + item + "\"" + " diminuita!");
	    	$('#reduceqty-modal').modal('show'); 
	    	// Reload page after closing the modal alert
	    	$('#reduceqty-modal').on('hidden.bs.modal', function () {
	    	 	window.location.reload();
	    	})
	    }
	});
}
...
  1. [alerts.php,它将包含所有引导程序模式警报,以在操作成功时显示(即“数量已更新!”)]

<!-- Reduce quantity modal -->
<div id="reduceqty-modal" class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Quantità ridotta</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
...

因此问题是reduceQuantity函数的“成功”部分无法正常工作。特别是不会显示模态。

我以为jQuery无法找到其选择器,因为它在包含的文件(alerts.php)中。我认为是这样,因为如果我将警报代码直接放入主文件admin-dashboard.php,则一切正常。

谢谢你!

javascript php jquery jquery-selectors
1个回答
0
投票
很抱歉浪费您的时间,谢谢大家!
© www.soinside.com 2019 - 2024. All rights reserved.