投稿されたフォーム フィールドから JSON リクエストを作成する次の PHP コードがあります。
<?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
)
)
)
)
JQuery Ajax を使用して同じ結果を達成し、<li>
タグ内のエラーの配列を出力するにはどうすればよいですか。