I have the following PHP code that created a JSON request from posted form fields.
<?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 )
prints the following.
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
)
)
)
)
How can i use JQuery Ajax to achieve the same results and print out the array of errors in <li>
tags.
jQuery.ajax
to make any other request? What part of the process is giving you problems? – DCoder Sep 22 '12 at 6:47