0

When i execute my page with JSON always have this response: [object object]. i have read in other post is a problem with not exist field, but this error appear too comment

$.each(result, function(i, row) { 
 console.log(JSON.stringify(row)); 
 $('#data-list').append('<li><a href="" data-id="' + row.id+ '"><h3>' + row.nombre + '</h3><p>' + row.denominacion + '</p></a></li>');
});

My javascript is:

$(document).on('pageinit', '#home', function(){ 
 var stuff = {
 id:null,
 nombre:null,
 precio:null,
 denominacion:null
 };
 var jsonString = JSON.stringify(stuff);
 $.ajax({
 url: "http://www.domain.com/ws.php?TIPO=OK" ,
 crossDomain: true,
 type:"GET",
 contentType: "application/json; charset=utf-8",
 dataType: "jsonp",
 async: true,
 data: jsonString,
 success: function (result) {
 alert(result);
 $.each(result, function(i, row) {
 console.log(JSON.stringify(row));
 $('#data-list').append('<li><a href="" data-id="' + row.id+ '"><h3>' + row.nombre + '</h3><p>' + row.denominacion + '</p></a></li>');
 });
 $('#data-list').listview('refresh');
 },
 error: function(xhr, status, error){
 console.log(status + '; ' + error+ ';');},
 jsonpCallback:function(response) {
 console.log('callback success'+response);
 }
 }); 
 });

In webserver is very simple only do a select and encapsule in JSON , i try with Content-type: application/javascript" and "Content-type: application/json" but same result,this is web service code

<?php
 include($DIRCONF . 'conf/VARIABLES.ini.php'); //incluimos configuración
 include($DIRCONF . 'JSON.php'); $tipo=$_GET['TIPO']; $json = new Services_JSON;
$conexion = mysql_connect(SERVIDOR_MYSQL, USUARIO_MYSQL, PASSWORD_MYSQL); mysql_select_db(BASE_DATOS, $conexion);
$que = "SELECT * FROM `DATOS`";
$res = mysql_query($que, $conexion) or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
 $data[] = $row; } //Cerramos la conexion a la base de datos mysql_close($conexion);
//header("Content-type: application/javascript"); header("Content-type: application/json"); echo json_encode($data) ; ?>
asked Mar 27, 2014 at 17:25

2 Answers 2

1

[object object] is what JavaScript gives you when you attempt to use an object as if it were a string. It is possible that your code is fine, but console.log('callback success'+response); is never going to log useful information. This might work:

console.log('callback success: ' + JSON.stringify(response));
answered Mar 27, 2014 at 17:30
Sign up to request clarification or add additional context in comments.

2 Comments

console.dir might also be an option
which this log show "callback success:undefined" page.html.html (línea 44) (Line of log) parsererror; Error: undefined was not called;[object Object], what mean this, men arrive function callback not defined values??? page.html (línea 41) (This line is where is function error)
0

I can find solution problem was Webservice, If you use jsonp: 'jsoncallback' need in WS return $_GET['jsoncallback'] how JSON object, if not put it, don't find any object and do error.

For example:

echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
answered Apr 3, 2014 at 7:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.