게시 된 양식 필드에서 JSON 요청을 생성 한 다음 PHP 코드가 있습니다.jQuery ajax를 사용한 PHP JSON 결과
<?php
if (isset($_POST['data']['Affiliate'])) { //Where ['data']['Affiliate'] is an array of posted field names of the form.
$data = $_POST['data'];
$base = 'https://api.whatever.com/Api?';
$params = array(
'Format' => 'json'
,'account' => $data['Affiliate']
);
$url = $base . http_build_query($params);
$result = file_get_contents($url);
$result = json_decode($result);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
print_r($result)
은 다음을 인쇄합니다.
stdClass Object
(
[request] => stdClass Object
(
[Format] => json
[account] => stdClass Object
(
[country] => US
[address1] => asdasd
[city] => asdasd
[zipcode] => asdasd
[phone] => asdasd
)
)
[response] => stdClass Object
(
[status] => -1
[data] =>
[errors] => Array
(
[0] => stdClass Object
(
[err_code] => 3
[err_msg] => A user already exists with this email address.
[attribute_name] => Email
[publicMessage] => User account or user is not valid.
)
[1] => stdClass Object
(
[err_code] => 1
[err_msg] => City cannot be blank.
[attribute_name] => city
)
)
)
)
어떻게 동일한 결과를 달성하고 <li>
태그 오류의 배열을 인쇄 할 JQuery와 아약스를 사용할 수 있습니다.
다른 요청을하기 위해 ['jQuery.ajax'] (http://api.jquery.com/jQuery.ajax/)와 같은 방법으로? 프로세스의 어떤 부분에서 문제가 발생합니까? – DCoder
@Dcoder, JSON으로 ajax 유형을 사용합니까? 양식을 serialize합니까? 어떻게하면 오류 배열을 정렬 할 수 있습니다. 이 부분에 대한 몇 가지 jquery 도움말이 필요합니다. – hedhud