I have a ajax call with json like this to get my data from php code and then display it in my page:
function get_customerdata(custID){
var serviceURL_customer = serviceURL + 'getcustomer.php';
$.ajax({
type: "GET",
url: serviceURL_customer,
async: false,
data: {id : custID},
dataType: 'json',
success: onSucess_displaycust
});
return false;
}
// --------------------------------------------------
function onSucess_displaycust(data)
{
var customer = data.item;
$('#custname1').text(customer.Name1);
... // other code
// --------------------------------------------------
// PHP code
$customer = $stmt->fetchObject();
...
$clean = utf8_string_array_encode($customer);
echo '{"item":' . json_encode($clean) .'}';
...
I want to put the variable
customer.Name1
in a div selector. This doesn't work. When i fetch the same data with the same php-script with $.getjson it is working fine without problems. I have to use $.ajax cause of syncron fetching data. Can anybody help to solve my problem?
This is a extraction of my json data:
//------------------------------------------
//json data
1. item: {ID:10011, UserID:XXX, Passwort:XXX, Name1:Bike Sport, Name2:XXX,…}
1. Name1: "Bike Sport"
This is the exact response of my json-data:
{"item":{"ID":"10011","UserID":"XXX","Passwort":"XXX","Name1":"Bike Sport", ...