通常當我想在一個PHP文件中創建新的內容和地方實現它在我的地盤我做這樣的事情(JS和PHP):發送多個PHP文件與AJAX
case 'someCasename':
...
include_once 'file.php';
break;
...
success: function(data){
$("#idSelector").html(data);
}
和新內容顯示在選定的元素上。
但我很好奇,如果它可能發送多個php文件在同一時間。不知道這是否真的有必要,而且我還沒有碰到過需要這樣做的單一時間,但我想到了這一點,並想問一問。這最後的代碼是最有可能非常非常錯誤的,但我只是想展示我的意思:
case 'someCasename':
...
$phpArray = array("file1" => include_once 'file1.php', "file2" => include_once 'file2.php', "file3" => include_once 'file3.php'):
echo $phpArray;
break;
...
success: function(data){
$("#idSelector").html(data.file1);
$("#idSelector").html(data.file2);
$("#idSelector").html(data.file3);
}
是這樣的,即使remotly可能嗎?你不能json_encode php文件可以嗎?
查看jQuery的load()方法。 http://api.jquery.com/load/ –