2015-02-23 40 views
-1

我想包括一個php文件在這種情況下,如何在ajax調用中包含一個php文件?

在ajax調用的文件中。例如,下面的代碼,.ajax網址是search.php,所以我想包含'fiel.php';在我的search.php中,我該怎麼做?

$.ajax({ 
    url:'search.php', 
    data:{ search_text: $(".result_tag").text() 
}, 
    error: function(){ 
     $('#find_members').html('<p>An error has occurred</p>'); 
}, 
    success: function(data){ 
     $("#find_members").html(data); 
}, 
    type:'POST' 
}); 

的search.php

<?php 
//this is search.php 

include 'file.php'; 

echo test(); //try to testing 
?> 

file.php

//this is file.php 
<?php 
function test(){ 
echo"hello";} 
?> 

的HTML

<div id="find_members"></div> 
+0

你可以在search.php中使用一個PHP'include'feil.php';'語句。 – 2015-02-23 15:25:17

+0

我已經嘗試過,但它不起作用。所以這就是爲什麼我想知道我做錯了什麼? – conan 2015-02-23 17:32:34

+0

如果沒有看到您的PHP代碼,我們無法知曉。表面上你的AJAX代碼看起來也有點變形。 – 2015-02-23 17:51:16

回答

-1

嘗試包括 'fiel.php' 變成 '的search.php'文件

+0

我已經嘗試過了。它不起作用。 – conan 2015-02-23 17:32:53