简体   繁体   English

从使用jquery load()加载的DIV中调用php函数

[英]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. 寻找一种调用php函数的方法,该函数在原始文件中包含“ functions.php”。

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. 这就是我的index.php文件中的内容,因此,当我单击链接时,它将加载(new.php)到(#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. 因此,在我的new.php文件中,我想调用一个位于functions.php文件中的函数,但是显然我得到了未定义的错误。

<?php some_func() ?>

I know you can just put another include 'functions.php' inside the new.php 我知道您可以在new.php内放另一个include'functions.php'

but since the functions.php contains mysql connections/queries and other includes etc.. i dont really want to keep reloading it. 但由于functions.php包含mysql连接/查询和其他包含等。。我真的不想一直重新加载它。

so is there any way i can reload the functions.php into the newly loaded div and call functions from it? 所以有什么办法可以将functions.php重新加载到新加载的div中并从中调用函数?

When you "load" new.php inside your div, you're only loading the resulting HTML code into the div. 当您在div中“加载” new.php时,您仅将结果HTML代码加载到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. 在这种情况下,最终的HTML代码将是对new.php的代码进行PHP处理的结果,该代码取决于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'; 在这种情况下,使用javascript访问文件的内容,绝对没有办法做到,只能放置include'functions.php include 'functions.php'; inside new.php. 在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. new.php将不会在“ inside” index.php中运行,因此将无法访问在那里定义的任何功能。

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

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