Tuesday, 15 April 2014

JSON decode (JQuery and JavaScript and little PHP) -



JSON decode (JQuery and JavaScript and little PHP) -

ho ho ho, can't decode response php.

json file:

{ "tablewidth":80, "thcolor": "51, 157, 221" }

this awesome php function:

public function lg_getjsonsettings(){ $file = file_get_contents("settings.json",true); $file = json_encode($file); echo $file; }

and javascript:

function lg_veriflychanges(){ result = $.getjson("/controller/lg_getjsonsettings"); console.log(result); }

on click, phone call js function. after response, firebug talking me :) , saying ? "zhu-zhu-zhu" :)

seriously:

response

object console log

i seek utilize json.parse(result) , $.parsejson, didn't work. error " json.parse: unexpected character @ line 1"

i hope, help.

your json valid uncertainty usage of getjson doesn't work way.

so, jquery.getjson() documentation suggest should utilize getjson method ,

$.getjson( "/controller/lg_getjsonsettings", function(json) { console.log(result); });

hope helps.

and using $.getjson("/controller/lg_getjsonsettings"); returns ajax state invalid json,

{ readystate: 1 }

thus causing issue

syntaxerror: json.parse: unexpected character @ line 1 column 2 of json data

json decode

No comments:

Post a Comment