On 06/28/2010 12:12 PM, barbe...@muohio.edu wrote: > Alright, so I have attempted to learn this JSON business, and have run > into some issues. I followed the tutorial at: > http://code.google.com/webtoolkit/doc/latest/tutorial/JSON.html > > Once I thought I understood it, I began to implement it within my > project. However, I cannot successfully retrieve the data. I have a > Data.php file that successfully connects to my server and reads in the > data, and formats as JSON data should be. Yet, when I run my project, > I get an HTTP response code of 0, and thus no data returned. > > I believe the problem to be with my url. I have noticed that the way > the tutorial above is set up, the user of the stock watcher > application must enter a symbol, and then the url is adjusted to > request that symbol. However, I have coded my Data.php to output all > entries in the table, as I want to access and display all entries upon > startup. Therefore, I am confused as to how my url should be formated. > Here is the code for my Data.php, excluding username and password > info: > > <? > header('Content-Type: text/javascript'); > header('Cache-Control: no-cache'); > header('Pragma: no-cache'); > > //username and password stuff here > > $con = mysql_connect($host, $user, $pass); > mysql_select_db($db, $con); > > echo '['; > > $result = mysql_query("SELECT * FROM sampleTreeTable"); > > $i = 0; > > while($row = mysql_fetch_array($result)) { > if($i > 0) { > echo ','; > } > $tItem = $row['treeItem']; > $tInfo = $row['treeInfo']; > > echo '{'; > echo "\"treeItem\":\"$tItem\","; > echo "\"treeInfo\":\"$tInfo"; > echo '}'; > > $i = $i + 1; > } > > echo ']'; > ?> > > This outputs my simple little test data as: > > [{"treeItem":"Requirements","treeInfo":"5}, > {"treeItem":"Decisions","treeInfo":"4}, > {"treeItem":"Tradeoffs","treeInfo":"6},{"treeItem":"Co- > occurances","treeInfo":"8}]
I think the zero result is caused by violating Same Origin Policy. Please ensure that's not happening. Also, I'd suggest not creating the response "by hand" PHP provides a json encoder. For example: json_encode(array (response_nonce => $_GET['openid_response_nonce'], openid_identity => $_GET['openid_identity']))); -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.