我想調用每個AJAX請求只有一個函數,但不知何故從他的PHP文件中的所有功能都被稱爲。如何使用ajax從一組函數中調用單個函數?
ajax.php
require_once "../lib/common-functions.php"; // here are the functions located.
subscribe();
subscribed();
unsubscribe();
delete_history();
deactivate_account();
和AJAX腳本:
$('#delete-history').on('submit', function (e) {
$.ajax({
type: 'post',
url: '../lib/ajax.html',
data: {
action: 'delete_history'
},
success: function (data) {
$("#message").html(data);
}
});
e.preventDefault();
});
如果我想只有功能delete_history()
然後我得到的消息從其他功能,如subscribe()
或全部在其他功能調用一旦。爲什麼?我在哪裏弄錯了。我可以在不將每個函數放入文件的情況下執行此操作。
使用'包括()',而不是'require_once()' –
@ Mr.coder,不,不工作。同樣的事情,從所有的PHP函數獲取消息。 – Adrian