批量生成别名Drupal - HTTP POST是必需的

时间:2017-09-26 13:25:13

标签: php ajax drupal drupal-7

我在“别名批量生成”期间遇到Drupal批处理问题。删除别名后,每次启动此操作时,我都会在文件“progress.js”中收到JS错误:

https://img11.hostingpics.net/pics/844245errorjs.png

Drupal.progressBar.prototype.sendPing = function () {
  if (this.timer) {
    clearTimeout(this.timer);
  }
  if (this.uri) {
    var pb = this;
    // When doing a post request, you need non-null data. Otherwise a
    // HTTP 411 or HTTP 406 (with Apache mod_security) error may result.
    $.ajax({
      type: this.method,
      url: this.uri,
      data: '',
      dataType: 'json',
      success: function (progress) {
        // Display errors.
        if (progress.status == 0) {
          pb.displayError(progress.data);
          return;
        }
        // Update display.
        pb.setProgress(progress.percentage, progress.message);
        // Schedule next timer.
        pb.timer = setTimeout(function () { pb.sendPing(); }, pb.delay);
      },
      error: function (xmlhttp) {
        pb.displayError(Drupal.ajaxError(xmlhttp, pb.uri));
      }
    });
  }
};

此JS错误的原因与batch.inc:

相关联
function _batch_do() {
  // HTTP POST required.
  file_put_contents("/var/www/docroot/tmp/requestType", $_SERVER['REQUEST_METHOD'], FILE_APPEND);
  if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    drupal_set_message(t('HTTP POST is required.'), 'error');
    drupal_set_title(t('Error'));
    return '';
  }

  // Perform actual processing.
  list($percentage, $message) = _batch_process();
  file_put_contents("/var/www/docroot/tmp/requestType", array('status' => TRUE, 'percentage' => $percentage, 'message' => $message), FILE_APPEND);
  drupal_json_output(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
}

实际上,$ _SERVER ['REQUEST_METHOD']等于“GET”而不是“POST”,这导致PHP错误。尽管如此,它确实是一个发送的POST请求,但是Drupal“看到”了一个GET请求。

因此,批量生成被阻止。

有什么想法吗?

如果您需要更多信息,请不要犹豫。

我的版本Drupal:7.55

0 个答案:

没有答案