getJSON结果导致XML解析错误? [英] getJSON results in XML parse error?

查看:111
本文介绍了getJSON结果导致XML解析错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript的新手,以为我会尝试从数据库中检索一些信息(并最终将其绘制成图形,希望如此!).

New to javascript and thought I would try retrieve some information from a database (and eventually graph it I hope!).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Flot Examples</title>
      <link href="layout.css" rel="stylesheet" type="text/css">
      <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
      <script language="javascript" type="text/javascript" src="../jquery.js"></script>
      <script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
   </head>
      <body>
      <h1>Test Javascript:</h1>


  <script type="text/javascript">
  $(function () {
      $.get("http://localhost:8000/activity?starttime=13129788041&endtime=0&hostid=1", function(data) {
          $.each(data, function(i,item){
              document.write(i);
          });
      });
  });
  </script>

   </body>
  </html>

如果我在浏览器窗口中键入"http://localhost:8000/activity?starttime = 13129788041& endtime = 0& hostid = 1"行,则会返回我要查找的内容:

The line "http://localhost:8000/activity?starttime=13129788041&endtime=0&hostid=1" returns what I'm looking for if I type it in a browser window:

{"1.313496422E9":[0.21000000000003638,448,12754,1.868579977195076]}

{"1.313496422E9":[0.21000000000003638,448,12754,1.868579977195076]}

但是在javascript中不起作用.

But doesn't work in the javascript.

如果我使用httpfox出现错误

If I look with httpfox there is an error

application/xml(NS_ERROR_DOM_BAD_URI)

application/xml (NS_ERROR_DOM_BAD_URI)

但是,如果我在httpfox中查看目录"选项卡,我实际上可以看到我需要的数据,但是存在XML解析错误.

But if I view the "contents" tab in httpfox I can actually see the data under I require but there is an XML parse error.

<?xml-stylesheet
  href="chrome://global/locale/intl.css" type="text/css"
  ?>
  <parsererror>
  XML Parsing Error: not well-formed Location: chrome://browser/content/browser.xul Line Number 1, Column 1:
  <sourcetext>
  {"1.313496422E9":[0.21000000000003638,448,12754,1.868579977195076]} ^
  </sourcetext>
  </parsererror>

NS_ERROR_DOM_BAD_URI似乎与跨域问题有关,但是我在实际服务器上本地工作,所以我应该能够访问数据吗?当我在httpfox的内容"标签中看到所需的确切数据时,为什么还会出现XML解析错误?

The NS_ERROR_DOM_BAD_URI seems to be about cross domain issues but I'm working locally on the actual server so should I be able to access the data? Also why is there an XML parse error when I can see the exact data I want in httpfox's "Content" tab?

我可能正在做一些非常业余的事情,但是任何帮助/想法/虐待都将受到欢迎!

I'm probably doing something horrendously amateur but any help/thoughts/abuse would be welcome!

干杯

Rob.

推荐答案

您的json来自服务器的格式不正确,或者...您实际上没有使用jQuery.getJSON函数.如果要使用jQuery.get,则需要将json数据类型指定为最后一个参数.

Either your json is malformed coming from the server or....you aren't actually using the jQuery.getJSON function. If you want to use jQuery.get, you need to specify the json data type as the last parameter.

http://api.jquery.com/jQuery.getJSON/

$.get("http://localhost:8000/activity?starttime=13129788041&endtime=0&hostid=1", function(data) {
          $.each(data, function(i,item){
              document.write(i);
          });
      }, 'json');

这篇关于getJSON结果导致XML解析错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆