简体   繁体   English

AJAX响应无法使用PHP require_once

[英]AJAX response not working with PHP require_once

I have issue with ajax response. 我有ajax响应的问题。 My test php file content looks like: 我的测试php文件内容如下:

<?php
  $values = array('value'=>'123',           
    'key'=>'Test'
  );
  echo json_encode($values);
?>

And everything works perfectly. 一切都很完美。 But problem is when I try but include database connection file then response stops. 但问题是当我尝试但包含数据库连接文件然后响应停止。

Basically if I add require_once 'database.php'; 基本上如果我添加require_once 'database.php'; Connection file content: 连接文件内容:

<?php
  $login = new PDO("sqlsrv:Server=SERVER;Database=db", "login", "pass");
?>

I already tried with 我已经试过了

ini_set('display_errors', 1);
  error_reporting(E_ALL);

but nothing. 但没什么。 This connection is fine, file location is fine as well. 这种连接很好,文件位置也很好。 And working with another website. 和另一个网站合作。

test.php file content: test.php文件内容:

<?php
  ini_set('display_errors', 1);
    error_reporting(E_ALL);

 require_once 'database.php';

$values = array('value'=>'123',                 
       'key'=>'test');
echo json_encode($values);
?>

file database.php in right location. file database.php在正确的位置。

Please go step by step:- 请一步一步走: -

1.) First of all you need to run your test.php file directly to ensure that there are no errors or warnings. 1.)首先,您需要直接运行test.php文件以确保没有错误或警告。

2.) If the file runs and echos the json data perfectly(without any warnings or errors), only then run the ajax call to get the response. 2.)如果文件运行并完美地回显json数据(没有任何警告或错误),则只有运行ajax调用才能获得响应。

3.) You will certainly get the response.if not,then the problem might in your ajax function. 3.)你肯定会收到回复。如果没有,那么你的ajax函数可能会出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM