我将以下内容硬编码到 jquery 中,并且我想移动代码以使用 ajax 从数据库中提取值。
我取回数据并使用 json_encode 传递它,但我需要保持相同的格式。
codes['851'] = new Array('11','12','20','21','23','24','30','41','43','44','45','48','50','52','53','54','55','60','70','110','120','205','206','207','208');
codes['852'] = new Array('11','12','20','21','23','24','30','41','43','44','45','48','50','52','53','54','55','60','70','110','120','205','206','207','208');
codes['522'] = new Array('11','12','20','21','23','24','30','41','43','44','45','48','50','52','53','54','55','60','70','120','205','206','207','208','209');
这是 json_encode 之前的 php 数组。
$codes = array();
codes['851'] = array('11','12','20','21','23','24','30','41','43','44','45','48','50','52','53','54','55','60','70','110','120','205','206','207','208');
codes['852'] = array('11','12','20','21','23','24','30','41','43','44','45','48','50','52','53','54','55','60','70','110','120','205','206','207','208');
codes['522'] = array('11','12','20','21','23','24','30','41','43','44','45','48','50','52','53','54','55','60','70','120','205','206','207','208','209');
我试图保持相同的格式,因为我不想重写脚本中的所有其他代码。是否可以匹配格式?