1
自動完成JSON響應格式我用jQuery的自動完成功能與Zend框架2 從服務器的響應必須JSON格式下面的JavaScript對象:與ZF2
[
{ value: 'Afghan afghani', data: 'AFN' },
{ value: 'Albanian lek', data: 'ALL' },
{ value: 'Algerian dinar', data: 'DZD' },
{ value: 'European euro', data: 'EUR' },
{ value: 'Angolan kwanza', data: 'AOA' },
{ value: 'East Caribbean dollar', data: 'XCD' },
]
這是我的阿賈克斯行動
public function autocompleteAction()
{
$Keyword = "c";
$product = $this->getProduitsTable()->getProduitComplete($Keyword);
foreach ($product as $item) {
$row['value'] = htmlentities(stripslashes($item->PROD_DESIGNATION));
$row['id'] = (int)$item->PROD_ID;
$row_set[] = $row;//build an array
}
$result = new JsonModel ($row_set);
return $result;
}
我收到這個結果
{
"0": {
"value": "BIc",
"data": 3
},
"1": {
"value": "Eastpak Valise \u0026agrave; roulettes, 78 L, Multicolore- Stripe In",
"data": 4
},
"2": {
"value": "Rainex Rock\u0027s 100 Sous-chemises",
"data": 5
},
"3": {
"value": "Roller correcteur rechargeable - Pritt - 4,2mm",
"data": 6
},
"4": {
"value": "10 Craies de couleur - Elami - Assortiment",
"data": 7
},
"5": {
"value": "Cartouche jet d\u0027encre Office Depot Compatible HP",
"data": 11
},
"6": {
"value": "Cartouche jet d\u0027encre HP C4837A 11 Magenta",
"data": 12
},
"7": {
"value": "Moniteur LCD HP 23cw 58.4 cm (23\u0026quot;)",
"data": 13
},
"8": {
"value": "Unit\u0026eacute; centrale Lenovo 90BJ003TFR",
"data": 14
},
"9": {
"value": "Ensemble PC ASUS UC K31ADE-FR008T + Ecran VS228DE 54.6 cm (21.5\u0026quot;)",
"data": 15
},
"10": {
"value": "Ordinateur portable ASUS Premium R511LJ 39.6 cm (15.6\u0026quot;) 6 Go Windows 8.1 64 Bits",
"data": 16
},
"modulenamespace": "Docs"
}
這個錯誤:
SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data
如何讓Rails運行在正確的格式生成JSON?
非常感謝您
,你可以把這裏的javascript代碼? –