简体   繁体   中英

Calling a php function from a DIV that was loading using jquery load()

Looking for a way to call a php function that has its include 'functions.php' in the original file.

This is what is in my index.php file, so when i click on a link it will load (new.php) into the (#container) div.

<?php include 'functions.php' ?>

<script type="text/javascript">
$(document).ready(function() {
  $('a').click(function(e) {
    $('#container').load(new.php).hide().fadeIn(500);
    return false;
  });
});
</script>

So in my new.php, i want to call a function that is located in functions.php, but obviously i get an undefined error.

<?php some_func() ?>

I know you can just put another include 'functions.php' inside the new.php

but since the functions.php contains mysql connections/queries and other includes etc.. i dont really want to keep reloading it.

so is there any way i can reload the functions.php into the newly loaded div and call functions from it?

When you "load" new.php inside your div, you're only loading the resulting HTML code into the div.

The resulting HTML code, in that case, will be the result of the PHP processing of new.php's, code, which depends on functions inside functions.php.

In that case, acessing the content of a file using javascript, there is absolutely no way to do that but placing include 'functions.php'; inside new.php.

Both files will be processed individually. new.php will not run "inside" index.php and therefore will not be able to access whatever functions are defined there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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