【问题标题】:PHP code not interpreted in AJAX request with Google App Engin PHP使用 Google App Engine PHP 在 AJAX 请求中未解释 PHP 代码
【发布时间】:2015-09-01 10:04:19
【问题描述】:

我正在尝试在 Google App Engine 上使用 AJAX 请求。 在我的开发环境中,一切正常,我的请求被正确解释。但是当我在生产中更新我的代码时,AJAX 请求的呈现是我的 php 文件中的代码(预期为 json)。就好像代码被解释为纯文本,而不是像 php。 这是我的脚本:

App.yaml 文件:

application: app-name
version: 1
runtime: php55
api_version: 1
threadsafe: true

handlers:

- url: /(.+\.(gif|png|jpg))$
  static_files: \1
  upload: .+\.(gif|png|jpg)$
  application_readable: true

- url: /web/css
  static_dir: web/css

- url: /web/js
  static_dir: web/js

- url: /web/img
  static_dir: web/img

- url: /web/fonts
  static_dir: web/fonts

- url: /
  script: index.php

- url: /add/update
  script: /service/formService.php

- url: /delete
  script: /service/deleteFormService.php

- url: /ajax/init
  script: web/js/ajax/init.php

- url: /ajax/suiviEtudes
  script: web/js/ajax/suiviEtudes.php

- url: /ajax/refreshProjectsPosition
  script: web/js/ajax/refreshProjectsPosition.php

Javascript 文件:

function initProjects(){
    $.ajax({ url: 'web/js/ajax/init.php',
        type: 'post',
        success: function(output) {
            alert(output);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest.status);
            console.log(errorThrown);
        }
    });
}

我的 php 文件:

<?php

require_once('../../../dao/dao.php');
include('../../../service/baseService.php');
include('../../../service/TownEPCIService.php');
include('../../../service/ContextService.php');
include('../../../service/LinkService.php');

$objProject = new project();
$baseService = new baseService();
$contextService = new contextService();
$linkService = new LinkService();
$townEPCIService = new TownEPCIService();

$project = $objProject->getAll();

$towns = $townEPCIService->getTownsByProjects($project);
$urbanismRules = $baseService->getUrbanismRule();
$ficabilityTypes = $baseService->getFiscabilityType();
$deliberations = $townEPCIService->getDeliberations();
$epcis = $townEPCIService->getEpciByProjects($project);
$studies = $baseService->getStudiesByProject($project);
$themes = $baseService->getThemes();
$states = $baseService->getStatesLabels();
$siteCaracteristics = $contextService->getCaracSiteByProject($project);
$indicators = $baseService->getIndicators();
$consultations = $contextService->getConsultationsByProject($project);

echo json_encode(['projets' => $project,
    'towns' => $towns,
    'urbanismRules' => $urbanismRules,
    'ficabilityTypes' => $ficabilityTypes,
    'deliberations' => $deliberations,
    'epcis' => $epcis,
    'etudes' => $studies,
    'themes' => $themes,
    'states' => $states,
    'siteCaracteristics' => $siteCaracteristics,
    'indicators' => $indicators,
    'consultations' => $consultations]);

感谢您的帮助。

【问题讨论】:

    标签: javascript php jquery ajax google-app-engine


    【解决方案1】:

    您的 ajax 正在发布到 /web/js/...,这在您的 app.yaml 中明确定义为静态路由;根据定义,静态路由提供静态内容,而不是解释脚本。

    您确实为 /ajax/init 定义了一个路由,您可能需要发布到该路由。但是,您的 PHP 文件本身应该位于静态 js 目录下。

    【讨论】:

    • 实际上,我的问题是我的 php 文件的位置。它在静态路由下。我试图改变它的位置,现在它工作得很好!我真的很感谢丹尼尔
    【解决方案2】:

    您的问题不清楚,在生产中您的 php 代码没有被解释? 如果答案是肯定的,如果启用了模块 php,则需要检查服务器配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 2020-05-04
      • 2014-11-14
      • 2019-02-09
      • 2016-04-20
      • 1970-01-01
      • 2013-07-02
      相关资源
      最近更新 更多