{"id":2680,"date":"2023-04-19T13:30:18","date_gmt":"2023-04-19T04:30:18","guid":{"rendered":"https:\/\/sirius10.net\/blog\/wordpress\/?p=2680"},"modified":"2023-04-19T13:30:20","modified_gmt":"2023-04-19T04:30:20","slug":"post-2680","status":"publish","type":"post","link":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/2023\/04\/19\/2680\/","title":{"rendered":"Javascript \u3067 PHP \u306e\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u3000web \u30da\u30fc\u30b8\u306b\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u30b5\u30fc\u30d0\u306e\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001javascript \u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002javascript \u304b\u3089 PHP \u306e\u30da\u30fc\u30b8\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u305d\u306e\u3068\u304d\u306b\u3001PHP \u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308b\u65b9\u6cd5\u3092\u63a2\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">javascript \u3067 PHP \u306e\u30da\u30fc\u30b8\u3092\u547c\u3073\u51fa\u3059<\/h2>\n\n\n\n<p>\u3000XMLHttpRequest \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001web \u30b5\u30fc\u30d0\u4e0a\u306e\u30da\u30fc\u30b8\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002GET \u3082 POST \u3082\u3067\u304d\u307e\u3059\u304c\u3001\u4eca\u56de\u306f PHP \u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u304b\u3059\u3060\u3051\u3067\u30c7\u30fc\u30bf\u306e\u9001\u4fe1\u306f\u5fc5\u8981\u306a\u3044\u3068\u8003\u3048\u3001\u7c21\u5358\u306a GET \u30e1\u30bd\u30c3\u30c9\u3067\u9001\u4fe1\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000PHP \u304b\u3089\u306e\u30c7\u30fc\u30bf\u306f\u3001json \u5f62\u5f0f\u3067\u53d7\u3051\u53d6\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002PHP \u306e\u547c\u3073\u51fa\u3057\u306e\u90e8\u5206\u306f\u3001\u6b21\u306e\u3088\u3046\u306a javascript \u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code file\"><code>  xhr = new XMLHttpRequest();\n  xhr.open('GET', '\u30b5\u30fc\u30d0\u4e0a\u306e PHP \u306e URL', true);\n  xhr.responseType = 'json';\n  xhr.send();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">PHP \u3067 json \u5f62\u5f0f\u3067\u30c7\u30fc\u30bf\u3092\u8fd4\u3059<\/h2>\n\n\n\n<p>\u3000PHP \u304b\u3089\u306f\u3001\u30c7\u30fc\u30bf\u306e\u307f\u3092 json \u5f62\u5f0f\u3067\u8868\u793a (\u8fd4\u3059) \u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code file\"><code>&lt;?php\n    $array = array(\"data1\" =&gt; 10, \"data2\" =&gt; 1000);\n    header(\"Content-Type: text\/javascript; charset=utf-8\");\n    echo json_encode($array);\n?&gt;<\/code><\/pre>\n\n\n\n<p>\u3000javascript \u3078\u8fd4\u3057\u305f\u3044\u30c7\u30fc\u30bf\u306f\u9023\u60f3\u914d\u5217\u3067\u6e96\u5099\u3057\u307e\u3059\u3002\u305d\u306e\u9023\u60f3\u914d\u5217\u3092 json \u5f62\u5f0f\u3067\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">XMLHttpRequest \u306e\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u3067\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308b<\/h2>\n\n\n\n<p>\u3000javascript \u5074\u3067\u306f\u3001\u30da\u30fc\u30b8\u306e\u30ed\u30fc\u30c9\u304c\u5b8c\u4e86\u3057\u305f\u3068\u304d\u306e\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u5185\u3067\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code file\"><code>  xhr = new XMLHttpRequest();\n  xhr.open('GET', '\u30b5\u30fc\u30d0\u4e0a\u306e PHP \u306e URL', true);\n  xhr.responseType = 'json';\n  xhr.addEventListener('load', function (response) {\n    let data = &lt;?=\"this.response\"?&gt;;\n    document.getElementById(\"data1\").innerHTML = data.data1;\n    document.getElementById(\"data2\").innerHTML = data.data2;\n  });\n  xhr.send();\n<\/code><\/pre>\n\n\n\n<p>\u3000\u30da\u30fc\u30b8\u5168\u4f53\u306e\u518d\u8aad\u8fbc\u3092\u884c\u308f\u305a\u306b\u5fc5\u8981\u90e8\u5206\u3060\u3051\u3092\u8868\u793a\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000web \u30da\u30fc\u30b8\u306b\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u30b5\u30fc\u30d0\u306e\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001javascript \u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002javascript \u304b\u3089 PHP \u306e\u30da\u30fc\u30b8\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u305d\u306e\u3068\u304d\u306b\u3001PHP \u304b\u3089\u30c7\u30fc\u30bf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-2680","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=2680"}],"version-history":[{"count":2,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2680\/revisions"}],"predecessor-version":[{"id":2692,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2680\/revisions\/2692"}],"wp:attachment":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=2680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=2680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=2680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}