Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX response not working with PHP require_once

I have issue with ajax response. My test php file content looks like:

<?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'; 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:

<?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.

like image 326
Klapsius Avatar asked Nov 09 '22 01:11

Klapsius


1 Answers

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.

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.

3.) You will certainly get the response.if not,then the problem might in your ajax function.

like image 198
akhil xec Avatar answered Nov 14 '22 21:11

akhil xec