我有以下 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
)
)
)
)
我如何使用 JQuery Ajax 来实现相同的结果并打印出<li>
标签中的错误数组。