javascript - JSON.parse give me an error but JSONLint say it's a valid json -


i'm trying make graphic jqplot extracting values vía mysql ajax, have read information this, i'm , me it's little embarrasing making question. it's causing me big headache :(

i've spent 20 days resolving can't alone myself, can me please? have tried (json.parse, parsejson, getjson, datatype html, datatype json, method , post.....)

i know easy... why crash when try json.parse(resultado) ?

http://jsonlint.com/ it's valid json, when try json.parse give me exception saying ("json.parse: unexpected character @ line 1 column 1 of json data")

it seems [ character

here php:

<?php include('conex.php'); $datos=mysql_query("select * meteorologia"); $arrdatos = array(); while ($rs=mysql_fetch_assoc($datos))     $arrdatos[] = array_map('utf8_encode', $rs); echo json_encode($arrdatos); ?> 

i obtain:

[{"fecha":"2015-01-01","ozono":"3","kt":"2","vv":"4"},{"fecha":"2016-03-03","ozono":"68","kt":"86","vv":"78"}] 

the js is:

try {     var strhtml = "";     $.ajax({             global: false,             datatype: "html",             async: false,             type: "post",             url: $("#form").attr('action'),             data: $("#form").serialize(),             success: function(resultado){                 alert('success!!'+resultado);                 console.log(typeof resultado);                 console.log(resultado);                 //var datosrecibidos = json.parse(resultado);                 //var datosrecibidos = jquery.parsejson(resultado);                 var lista = "";                 $.each( resultado, function( key, value ) {                         if(value.fecha == "2015-01-01")                         {                             alert('si!!');                         }                         else                         {                             alert('sino!!');                         }                 });             },             error: function(data){                 alert('error!!: '+data);             }     }); } catch(ex) {     alert("catch!!"+ex); } 

with $each key value ... can move inside array?

after trying lot of things (changing datatype json,html,..., method get, post...)

i debugging address file:///c:/xampp/htdocs/traerdatos/index.html

instead of http://localhost/traerdatos/index.html

so solution change address localhost

(thanks reformed helps me vision)

novel error =)


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -