javascript - calling php function from jquery ajax with include statement error -
i have problem include statements. have several php files loaded when page loaded , called 1 time again jquery ajax calls. because of ajax calls don't have php script in function , getting error includes statement when phone call them different location (the ajax call). illustration main page includes php script:
<div id="controlpanelform"> <?php include "lib/getcontrolpanel.php"; ?> </div>
here first few lines of getcontrolpanel.php file:
<?php include_once("../etc/includes.php"); ...do something...
here ajax call:
function getcontrol(teamid) { $.ajax({ type: "get", data: {teamid: teamid}, url: "./lib/getcontrolpanel.php", datatype: "html", async: true, success: function(response) { $('#controlpanelform').html(response); } }); }
so problem when phone call php script ajax phone call error:
include_once(../etc/includes.php): failed open stream: no such file or directory in
if alter relative path, original include main page doesn't work...
how can prepare issue?
thanks in advance!
include_once(../etc/includes.php): failed open stream: no such file or directory in
this error indicates file @ '../etc/includes.php' doesn't exist. can see current working directory using getcwd()
determine relative links pointing.
relative paths, however, pain. never utilize them. of projects contain config.php file containing configuration values:
// paths , urls define('site_path', '/var/www/my_website/'); define('site_url', 'http://localhost/my_website/');
now can absolute. modifying example:
<div id="controlpanelform"> <?php include site_path . 'lib/getcontrolpanel.php'; ?> </div>
getcontrolpanel.php:
<?php include_once(site_path . 'etc/includes.php');
lots more can done these defines such creating functions loading files, sending redirect headers, etc.
on side note, test ajax page going straight using web browser prior debugging ajax call. way can tell whether problem php problem or javascript problem.
php javascript jquery include
No comments:
Post a Comment