0

I will try to explain my problem in a simple way. My code looks like these.

A web page, systemView.php, has following code

<?php require_once 'Common_Function.php'; ?>
<head>
    <script src="jF.js"></script>
</head>
<html>
     <div id="one"> <?php A(); ?> </div>
     <div id="two">  </div>
</html>

Common_Function.php is

<?php
    include 'systemView_Function.php';
    include 'database.php';
?>

systemView.php has A() as well as B()

<?php
    function A() {
        D(); // a function in database.php
        //and show a few button on the page
    }
    function B($number) {
        D(); // a function in database.php
        //some codes to show something in the page
    }
    if (isset($_POST['B'])) { 
        B($_POST['B']); 
    }
?>

A() function will show some buttons on the page when called. When one of the buttons is clicked. javascript will then call B() by ajax. This function in js is

$(".abutton").click(function(){
    $("#two").empty();
    var number = parseInt($(this).text());
    $.ajax({
        url: "./systemView_Function.php",
        type: "POST",
        data: {"B": number},
        dataType: "JSON",
        success: function(data) {   
            $("#two").append(data);
        }
    });
})

Now the problem is when D() is not included in B(), the codes run successfully and shows something in id="two" div. However, if D() is included in B(), console in browser shows errors, and nothing in second div.

5
  • What are the errors in the console? Commented Jan 31, 2015 at 8:30
  • database.php isn't included in systemView.php is it? Commented Jan 31, 2015 at 8:32
  • @TZHX Chrome shows POST http://localhost:8888/systemView_Function.php 500 (Internal Server Error) Commented Jan 31, 2015 at 8:34
  • do i need to include it, as A() runs successfully? Commented Jan 31, 2015 at 8:35
  • Why is this tagged Java? Commented Jan 31, 2015 at 9:10

1 Answer 1

1

My guess is that, because you don't reference database.php in your systemView.php page, PHP cannot find the D() function and so throws an error.

A() runs because it is called from a page that has it in scope (from CommonFunctions.php), but when B() is called -- being a new request -- it doesn't know what to look for.

Sign up to request clarification or add additional context in comments.

2 Comments

i include 'database.php' in B() now, and it works. Thank you!
Glad I could be of some assistance. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.