0
ajax試圖將數據發佈到文件中的文件中是否可以調用另一個文件中的函數?從文件中調用另一個文件ajax試圖將數據發佈到
ajax試圖將數據發佈到文件中的文件中是否可以調用另一個文件中的函數?從文件中調用另一個文件ajax試圖將數據發佈到
如果你不能夠使用JavaScript回調,您可以使用POST變量火的功能在文件2.
文件1碼將發個帖子變量稱爲「call_function」與無論是真或錯誤的價值。
文件2代碼:
<?php
if($_POST['call_function'] == 'true')
{
file2function();
}
function file2function()
{
// do your stuff after loaded into file 1
}
?>
你可以嘗試的eval():
文件1個代碼:
$.ajax({ url: "two.php", type: "POST", data: data, cache: false, success: function (html) { alert(html); } });
文件2代碼:
<?php
if(isset($_POST['success'])) eval($_POST['success']);
// should run the function in your variable
?>
可能,但你沒有給我們太多的工作在這裏。什麼語言? Ajax調用發佈到哪種文件? – Schwartzie 2011-02-03 21:40:03
我很抱歉它的PHP。我在index.php裏面有ajax函數,這個函數把數據發佈到data.php。但是在data.php中有與DB通信的函數。 index.php - > data.php - > insertintodb.php – Dhiraj 2011-02-03 21:45:43