【发布时间】:2020-03-09 17:33:08
【问题描述】:
我有这个 Ajax 调用:
$('#directory_select_form').submit(function(e) {
$('#loader').show();
$('#order_number_submit_btn').prop('disabled', true);
e.preventDefault();
$.ajax({
url: 'includes/confirmation_emails/process_directory_request.php',
type: 'POST',
dataType: 'json',
data: $(this).serialize(),
success: function(data) {
console.log(data);
$('#loader').hide();
$('#order_number_submit_btn').prop('disabled', false);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#loader').hide();
$('#order_number_submit_btn').prop('disabled', false);
}
})
});
process_directory_request.php 包含一个shell_exec 命令:
<?php
$selected_directory = $_POST['selected']; //<-- This will be used later. Hard coded for now
$order_number = $_POST['orderId']; //<-- This will be used later. Hard coded for now.
$command = shell_exec('ssh remoteServer grep -o "Order Number 1234567" /mnt/tank/TECH/"MySQL\\ Data\\ Archives"/path/to/the/file');
echo json_encode($command);
它崩溃了,因为由于某种原因它进入了一个无限循环。如果我从命令行运行命令,它会按预期运行。
我不能使用this answer,因为开头是ssh。我正在远程运行命令。
是什么导致了这个无限循环?我不明白。我正在将 ajax 响应数据打印到控制台,并且一遍又一遍地是同一行。
编辑 这是我的开发控制台中的输出,但实际上是很多倍:
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
/mnt/tank/TECH/MySQL Data Archives/path/to/the/file:Order
【问题讨论】:
-
我在这里看不到任何循环,无限或其他。你的意思是你的AJAX请求被重复触发了吗?还有什么?
-
我不知道具体多少次,但它使我的脚本崩溃,因为它的内存不足。输出是预期的结果,但一遍又一遍。
-
你能澄清一下这里重复了什么吗?在浏览器的调试工具中,AJAX 请求是否重复发出?该请求的每个实例都是您所期望的吗?当您调试时,这个
submit事件处理程序是否被重复触发?请详细说明。 -
是的,我将编辑我的问题以显示一些输出。给我一分钟。
-
这不是一个无限循环。这是一个引用问题,它只是匹配单词
Order而不是整个字符串Order Number 1234567。因此,您将获得文件中包含该单词的所有行,而不仅仅是指定的数字。
标签: php ajax ssh shell-exec