hibbsusan
asked on
getJSON returning oddly even though seems to be formatted correctly
Hello!
When I'm trying to use getJSON, no results are returned at all.
and when i use what the jquery.net seems to indicate is just the lengthened version:
I get an unordered list returned with one character from the array per bullet point. Sample:
[•{
•"
•a
•"
•:
•"
•s
•u
•s
•a
•n
•h
•i
•b
•b
•a
•r
•d
•"
•,
•"
•b
•"
•:
•"
•I
•n
•d
address_process_php
This seems to work okay because when I go to address_process.php, I get:
{"a":"susan hibbard","b":"Independent' s Service"}{"a":"susan hibbard","b":"isco"}{"a":" susan","b" :"indep"}
Many thanks for any insight!
When I'm trying to use getJSON, no results are returned at all.
and when i use what the jquery.net seems to indicate is just the lengthened version:
function get()
{
$.ajax({
url: 'address_process.php',
success: function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
}
});
I get an unordered list returned with one character from the array per bullet point. Sample:
[•{
•"
•a
•"
•:
•"
•s
•u
•s
•a
•n
•h
•i
•b
•b
•a
•r
•d
•"
•,
•"
•b
•"
•:
•"
•I
•n
•d
address_process_php
while ($row = mysql_fetch_array($result))
{
echo json_encode(array("a" => $row['attn'], "b" => $row['company_name']));
}
This seems to work okay because when I go to address_process.php, I get:
{"a":"susan hibbard","b":"Independent'
Many thanks for any insight!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
could you provide a link to your page?
ASKER
actually, i forgot to upload the new php info before I posted that. After I make that change, nothing happens at all.
$arr = array(); // create an empty array
while ($row = mysql_fetch_array($result)) {
$arr[] = array("a" => $row['attn'], "b" => $row['company_name'] ); // push all object inside the array
header("Content-type: application/json"); // set the header, it's safe
echo json_encode($arr); // encode the full object to a json string object
could you provide a link to your page?
ASKER
and when I go to the address_process.php page, I see the folowing
but I'm not aware of having sent any header information; this is the entire page:
[{"a":"susan hibbard","b":"Independent's Service"}]<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/iscosand/public_html/php/RegistrationForm/source/address_process.php:37) in <b>/home/iscosand/public_html/php/RegistrationForm/source/address_process.php</b> on line <b>36</b><br />
[{"a":"susan hibbard","b":"Independent's Service"},{"a":"susan hibbard","b":"isco"}]<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/iscosand/public_html/php/RegistrationForm/source/address_process.php:37) in <b>/home/iscosand/public_html/php/RegistrationForm/source/address_process.php</b> on line <b>36</b><br />
[{"a":"susan hibbard","b":"Independent's Service"},{"a":"susan hibbard","b":"isco"},{"a":"susan","b":"indep"}]
but I'm not aware of having sent any header information; this is the entire page:
<?php
session_start();
$u = $_SESSION['u'];
$con = mysql_connect('localhost', 'iscosand_admin', '123');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("iscosand_login1", $con);
if (!$con)
{
die(mysql_error());
}
$user = mysql_query("SELECT id_user FROM users WHERE email='".$u."'");
while ($row = mysql_fetch_array($user))
{
$id_user = $row['id_user'];
}
$result = mysql_query("SELECT * FROM billing_address WHERE id='".$id_user."'");
//$temp = mysql_num_rows($result);
//echo 'temp is '.$temp;
if (!$result)
{
die(mysql_error());
}
else
{
$arr = array(); // create an empty array
while ($row = mysql_fetch_array($result))
{
$arr[] = array("a" => $row['attn'], "b" => $row['company_name'] ); // push all object inside the array
header("Content-type: application/json"); // set the header, it's safe
echo json_encode($arr); // encode the full object to a json string object
}
}
?>
if look my code ID:37060449
I did NOT put the header and the next line inside the while loop!
I did NOT put the header and the next line inside the while loop!
ASKER
no! you did not! :) sry.
and i posted those so quickly i didn't see your multiple requests for a link to the page..
http://www.iscosandbox.com/php/RegistrationForm/source/newadd.php
and i posted those so quickly i didn't see your multiple requests for a link to the page..
http://www.iscosandbox.com/php/RegistrationForm/source/newadd.php
:))
what about the credentials?
what about the credentials?
ASKER
this worked so smoothly! it's going great!
five-hundred'd!
thank you so much :)
five-hundred'd!
thank you so much :)
ASKER
Open in new window
prints to screen:
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined
• undefined