2012-11-07 2 views
0

내가 아약스를 사용하여 컨트롤러의 응답을 수집하려고 작동하지하지만 난이 코드가 없습니다JQuery와 아약스의 성공은

$.ajax({url: url, 
     success: function(data) { 
     alert("hi"); //no work. 
    } 
}); 

을 컨트롤러로 돌려주는 :

return new Response($venta->getId()); 

컨트롤러에서 호출이 성공적으로 번호를 반환합니다. 그러나 성공은 섹션에 포함되지 않습니다.

+0

. 요청한 페이지는 jQuery Ajax에서 가져올 수있는 ID를 표시해야한다. –

+0

페이지 반환 ID – Bicu

+0

반환 새 응답 (json_encode ($ array), 200, array ('Content-Type', 'text/json')); 단지 번호 json 작동하지 ??? – Bicu

답변

0

아약스 jQuery 코드 :

$.ajax({ 
    dataType: 'json', 
    url:url, 
    success: function(data) { 
    alert("hi"); 
    } 
}); 

반환 URL : 브라우저

{"id":89} 

에서

$array['id'] = $venta->getId(); 
return new Response(json_encode($array), 200, array('Content-Type', 'text/json')); 

표시없이 쇼 경고 (HI) 그 이유는 무엇입니까? 감사.

+0

질문에 대한 추가 정보를 대답으로 사용하지 마십시오. –

0

HTML :

<html> 
<head> 
     <script 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" 
     type="text/javascript"></script> 
    <script type="text/javascript"> 
    url='./responsetest.php'; 
    $.ajax({ 
     type: 'GET', 
     dataType: 'json', 
     url:url, 
     success: function(data) { 
     alert("hi"); 
     }, 
    error: function(data) { 
     console.log(data); 
    } 
    }); 
     </script> 
</head> 
<body> 
    <div id="display"></div> 
</body> 
    </html> 

PHP 파일 : responsetest.php에만 그나마 반환해야하지만 실제로 그것을 인쇄

<?php header('content-type: application/json; charset=utf-8'); 
    $msg = array('id' => 89); 
    echo $_GET['callback'].json_encode($msg); 
    ?> 
+0

오류 기능을 포착하여 얻은 결과를 확인하십시오. –

관련 문제