2010-11-30 2 views

답변

4
jQuery를에

이 구현 될 것입니다 뭔가 :

var user = {}; 

$.ajax({ 
    url: 'http://mysite.com/api/user.json', 
    data: {'id': '42'}, 
    success: function(data){user = data;}, 
}); 

$('#name').val(user.name); 
$('#email').val(user.email); 
6

PHP 측에서는 json_encode()을 사용하여 데이터를 JSON으로 변환하고 작성한 다음 종료하십시오. 베스트 수신 측이 JSON로 인식 확인하기 위해, 먼저 콘텐츠 형식 헤더를 보내

<?php 
$response_data = whatever_function(); 
$response = json_encode($response_data); 
header("Content-type: text/json"); 
echo $response; 
exit; 

를 클라이언트에서, 당신의 최선의 방법은 jQuery를에 내장 된 AJAX 기능으로 기존 AJAX 프레임 워크를 사용하는 것입니다. 가정 스크립트는 http://example.com/ajax.php에 있고, 클라이언트 페이지의 jQuery 적절한 조각 같은 것을 갈 것, http://example.com/ajaxclient.html에 있습니다 :

$.getJSON('ajax.php', { /* GET data goes here */ }, function(data) { 
    /* data contains the values you sent in your PHP script */ 
}); 
이 같은
관련 문제