2012-03-16 7 views
0

안녕하세요, 저는 jquery를 사용하여 ajax 쿼리를 실행하려고합니다. 로컬에 저장된 .txt 파일을 사용하면 문제가 없습니다. PHP를 생성 한 json을 쿼리하려고 할 때마다 문제가 발생합니다. 나는 file.txt를 복사본을 만들다면/나는 http://localhost/public/ProductCatalog/searchindex/txt.php에서 생성하고 매개 변수로 사용하는 것과 동일한 정보를 붙여, 나는이 콘텐츠를json을 사용하여 .txt 파일에서 json을 얻을 수 있지만 json을 사용하여 json을 생성했습니다.

$('#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(); 
}); 
}); 

: 여기 코드입니다. 코드를 실행하면 아무 것도 실행되지 않습니다.

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

확인 후 txt.php 출력이 필요합니다. –

관련 문제