I have a problem with WordPress and ajaxAjax.
This is my javascriptJavaScript part (I trimmed it a bit):
The script gets the ajaxAjax response from admin-ajax. Unfortunately the console throws an error when it gets to the each
statement in javascriptthe JavaScript code... it says:
"Uncaught TypeError: Cannot use 'in' operator to search for '4' in Array".
If I do a console.log of my "posts" var I get a string 'Array'. No matter how I pass the $list
variable in PHP it will always return a string. The query returns posts elsewhere, so it's not empty. I tried without json_encode
, with and without declaring header, using wp_send_json()
, putting ob_clean()
before echoing the array, putting the array into an array... But it always gets into ajaxajax
as a string Array
and each
cannot cycle through it.
This should be a very simple thing and I can't understand why it's not working. I don't have other javascriptJavaScript or phpPHP errors or warnings and everything else runs fine. I'm calling it a day and getting to sleep while posting this on stack :)