現在の言語: 日本語 |
単純リクエスト |
ajax |
[test1.php]
// -----------------------------------------------------
// 1. CORSヘッダーの設定 (最も重要)
// -----------------------------------------------------
//アクセスを許可するオリジンを指定します。
//このサンプルでは、全てのオリジンからのアクセスを許可しています。
header("Access-Control-Allow-Origin: *");
//レスポンスのタイプがJSONであることをブラウザとJSに伝えます
header("Content-Type: application/json; charset=UTF-8");
//-----------------------------------------------------
//2. 実際のリクエスト処理
//-----------------------------------------------------
//返すデータを設定します
$data = array(
"message" => "Hello test1.html",
"user_id" => 1234567890,
"source" => "test data"
);
//データをJSON形式に変換して出力します
echo json_encode($data);
[test1.php]
// -----------------------------------------------------
// 1. Setting CORS headers (most important)
// -----------------------------------------------------
// Specifies origins allowed to access.
// This sample allows access from all origins.
header(“Access-Control-Allow-Origin: *”);
// Informs the browser and JS that the response type is JSON
header(“Content-Type: application/json; charset=UTF-8”);
//-------- ---------------------------------------------
//2. Actual Request Handling
//------------------------------------------- ----------
// Set the data to return
$data = array(
“message” => “Hello test1.html”,
“user_id” => 1234567890,
“source” => “test data”
);
// Convert the data to JSON format and output it
echo json_encode($data);
| 著作権情報 |
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームページおよびアプリ等を利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |