{"id":2153,"date":"2022-08-30T15:22:29","date_gmt":"2022-08-30T15:22:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/04\/json-encoded-array-comes-out-as-null-in-php-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:29","modified_gmt":"2022-08-30T15:22:29","slug":"json-encoded-array-comes-out-as-null-in-php-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/json-encoded-array-comes-out-as-null-in-php-collection-of-common-programming-errors\/","title":{"rendered":"JSON encoded array comes out as null in PHP-Collection of common programming errors"},"content":{"rendered":"<p>I am making a small drag and drop app using jQuery UI&#8217;s Sortable feature. The jQuery works fine but when I try to encode the array of all of the lines in their order, the PHP script on the other side reads the array as <code>NULL<\/code> and I cannot figure out why. Here&#8217;s everything in the order that they appear in my first script:<\/p>\n<p>The HTML<\/p>\n<pre><code>\n    \n    REORDER\n\n\n<\/code><\/pre>\n<ul id=\"photo-selector\">\n<li id=\"img1\"><code><img decoding=\"async\" src=\"images\/img1.jpg\" \/><\/code><\/li>\n<li id=\"img2\"><code><img decoding=\"async\" src=\"images\/img2.jpg\" \/><\/code><\/li>\n<li id=\"img3\"><code><img decoding=\"async\" src=\"images\/img3.jpg\" \/><\/code><\/li>\n<li id=\"img4\"><code><img decoding=\"async\" src=\"images\/img4.jpg\" \/><\/code><\/li>\n<li id=\"img5\"><code><img decoding=\"async\" src=\"images\/img5.jpg\" \/><\/code><\/li>\n<li id=\"img6\"><code><img decoding=\"async\" src=\"images\/img6.jpg\" \/><\/code><\/li>\n<\/ul>\n<pre>\n<\/pre>\n<p><code>The JS<\/code><\/p>\n<pre><code><code>$(document).ready( function(){\n\n    var formOrder = document.getElementById('reorder');\n    formOrder.addEventListener('submit', function(){\n        var post_ids_field= document.getElementById('post_ids');\n        var ul_id = document.getElementById(\"photo-selector\");\n        var post_ids = ul_id.getElementsByTagName(\"li\");\n        post_ids_field.value = JSON.stringify(post_ids);\n        alert(\"check\");\n    });\n\n});\n<\/code><\/code><\/pre>\n<p>When clicking the &#8220;REORDER&#8221; button in the form up top it sends to <code>orderupdate.php<\/code> which is as follows<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-04 00:53:01. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am making a small drag and drop app using jQuery UI&#8217;s Sortable feature. The jQuery works fine but when I try to encode the array of all of the lines in their order, the PHP script on the other side reads the array as NULL and I cannot figure out why. Here&#8217;s everything in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2153","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2153"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2153\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}