我试图将我的php数组传递给jQuery数组,但我在chrome控制台上遇到了这个错误,未捕获语法错误:意外的标记<;
功能。php
/*Call Jquery for dropdowns*/
function mytheme_custom_scripts(){
if ( is_page(\'Support\')) {
$scriptSrc = get_stylesheet_directory_uri() . \'/js/freshdeskdata.js\';
wp_enqueue_script( \'myhandle\', $scriptSrc , array(), \'1.0\', false );
}
}
add_action( \'wp_enqueue_scripts\', \'mytheme_custom_scripts\' );
/*End - Jquery*/
add_filter(\'wpcf7_form_tag_data_option\', function($n, $options, $args){
...
// Category
if (in_array(\'category.provider\', $options)){
...
// Getting results
$result = curl_exec($ch); // Getting jSON result string
curl_close($ch);
$data = json_decode($result, true);
global $choice; // This is my array
$choice = $data[0][\'choices\'];
ksort($choice);
return array_keys($choice);
}
// default - do not apply any changes within the options
return null;
}, 10, 3);
/js/freshdeskdata。js公司jQuery(function ($) {
$(document).ready(function() {
$("#main-category").on(\'change\', function() {
var arrayFromPHP = <?php echo json_encode($choice); ?>;
var $el = $("#sub-category");
$el.empty();
alert("arrayFromPHP");
});
});
});