2012-03-16 6 views
0

jqueryを使用してajaxクエリを実行しようとしています。ローカルに保存された.txtファイルを使用しても問題はありません。この問題は、jsonが生成したPHPをクエリしようとするたびに発生します。私はfile.txtのコピーを作成するのであれば/私はhttp://localhost/public/ProductCatalog/searchindex/txt.phpから生成し、それをパラメータとして使用するのと同じ情報を貼り付け、その後、私はコンテンツを取得jqueryを使用してjsonを使用して.txtファイルからjsonを取得できますが、PHPでは生成されません。

$('#find').click(function(){ 
$.getJSON('http://localhost/public/ProductCatalog/searchindex/txt.php', function(data) { 
var items = []; 
$.each(data, function(key, val) { 
     pushStr = '<div class="prod-container">'; 
     pushStr += ' <div class="prod-image-container"><img class="prod-img" src="' + val['foto'] + '"/></div>'; 
     pushStr += ' <div class="prod-desc-container">' + val['title'] + '</div>'; 
     pushStr += ' <input class="id" type="hidden" value="' + val['id'] + '"/>'; 
     pushStr += ' <input class="title" type="hidden" value="' + val['title'] + '"/>'; 
     pushStr += '</div>'; 
     items.push(pushStr); 
    }); 

    items.push('<div style="clear:both;"></div>'); 
    $('#prod-body').html(items.join('')); 
    $('img.prod-img').each(function (index, element){ 
     fitImage(element, 75, 110); 
    }); 
    makeDraggable(); 
}); 
}); 

:ここでは、コードです。コードをそのまま実行するとHowerverは何も実行されません。

file.txtを例:ここ

{ 
    "item1": { 
     "foto": "item1.jpg", 
     "title": "Teclado roland fantom-g8 las teclas con contrapeso", 
     "id": "1", 
     "price": "56090.25" 
    }, 
    "item2": { 
     "foto": "item2.jpg", 
     "title": "Teclado roland v-piano lo cambia todo", 
     "id": "1", 
     "price": "85501.79" 
    }, 
    "item3": { 
     "foto": "item3.jpg", 
     "title": "Teclado roland ax-synth teclado 49 teclas (dinÃ", 
     "id": "1", 
     "price": "13034.05" 
    }, 
    "item4": { 
     "foto": "item4.jpg", 
     "title": "Teclado roland fantom g-6 fuente de sonido avanzada", 
     "id": "1", 
     "price": "39989.14" 
    }, 
    "item5": { 
     "foto": "item5.jpg", 
     "title": "Teclado gw-8l roland gw-8l -bstock", 
     "id": "1", 
     "price": "11627.32" 
    }, 
    "item6": { 
     "foto": "item6.jpg", 
     "title": "Teclado disney", 
     "id": "1", 
     "price": "605.00" 
    } 
} 

は、PHPのコードです:

// action body usinf zend framework 
    $this->getHelper('viewRenderer')->setNoRender(); 
    $index = Zend_Search_Lucene::open('/data/prod-catalog'); 
    $results = $index->find('teclado roland'); 
    $first = $this->_request->getParam('first'); 

    header('Cache-Control: no-cache, must-revalidate'); 
    header('Content-type: application/json'); 

    $i=1; 

    echo '{'; 
    foreach ($results as $result){ 
     echo '"item'.$i.'": {'."\n"; 
     echo ' "foto": "'.$result->foto.'",'."\n"; 
     echo ' "title": "'.ucfirst(strtolower($result->titulo)).'",'."\n"; 
     echo ' "id": "'.'1'.'",'."\n"; 
     echo ' "price": "'.ucfirst(strtolower($result->precio)).'"'."\n"; 
     echo ($i<count($results) && $i<6)? '},'."\n": '}'."\n".'}'; 
     $i++; 
     if($i==7){ 
      break; 
     } 
    } 
+0

あなたのパケットスニッファーは、あなたが代わりに何を得ていると言いますか? –

+0

申し訳ありませんが、ブラウザのコンソールが実際にファイルをダウンロードしても、それ以降は何も実行されません。 – awavi

+0

あなたはtxt.phpのコンテンツを投稿できますか?ただ –

答えて

1

セキュリティ上の問題でした。ローカルのjs機能を使ってhtmlを実行していましたが、サーバーはそれを許可しませんでした。サーバーで実行したら解決しました。

0

」や「あなたはにaddslashes()でJSONを構築している、あなたの文字列から

をエスケープしてみます。
+0

私はこれをやっていますが、まだ応答はありません – awavi

+0

OKあなたのtxt.php出力が必要です。 –

関連する問題