我有一個PHP函數:相當於PHP的Javascript的XMLHttpRequest的
function saveSnapshot() {
header("Content-Type: application/JSON: charset=UTF-8");
global $CFG;
$resString = "{\"Success\": \"True\"}";
$snapshotName = getArgument("snapshotName");
$user = getArgument("userId");
$ttd = getArgument("ttData");
$fed = getArgument("feData");
$ttData = json_decode($ttd, true);
$feData = json_decode($fed, true);
我打電話使用Javascript Ajax調用這個函數:
xhttp.open("POST", "myfile.php", true); // asynchronous
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("reqType=saveNewSnapshot&newSnapshotName=" + newSnapshotName + "¤tSnapshotName=" + currentSnapshotName +
"&configId=" + currentConfigId + "&ttData=" + JSON.stringify(timeTable) +
"&feData=" + JSON.stringify(fixedEntry));
現在,而不是調用PHP文件saveSnapshot功能使用javascript ajax,我想從其他一些PHP文件調用saveSnapshot函數。
我該怎麼做?我該如何撥打電話?我如何傳遞參數?
你可以去看一下PHP'cURL' - http://codular.com/curl-with-php – Diego
有幾種方法,但我更喜歡捲曲作爲最簡單的方法。 – richbai90
@Diego你可以發表一些關於此的代碼嗎? – user5155835