显示一些错误未捕获的ReferenceError: [英] Show some error Uncaught ReferenceError:

查看:155
本文介绍了显示一些错误未捕获的ReferenceError:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经打电话给 json 文件并显示一些错误,请你帮帮我



显示错误 Uncaught ReferenceError:未定义marketlivedata



 < script src =https://ajax.googleapis.com/ ajax / libs / jquery / 1.11.1 / jquery.min.js>< / script><!DOCTYPE html>< html xmlns:xhtml =http://www.w3.org/1999/xhtml xmlns:g =http://base.google.com/ns/1.0>< head> < title>数据调用json< / title> < script type =text / javascript> // ===================== $(document).ready(function(e){// alert('hello'); // var marketlivedata;} ); // ===================== function getUserData(){$ .ajax({type:GET,url:http://xxxxxxxxx.xxxxxxx。 com / xxxxxxx.json,dataType:'jsonp',crossDomain:true,success:function(data){// $('#ajexLoaderSec')。hide(); console.log(data);},错误:function (e){alert(连接服务器时出错。请在一段时间后尝试);}}); }; getUserData(); < /脚本>< /头><身体GT; gsdf sdf sdfsd sdf sd< / body>< / html>  



我的json格式是

  marketlivedata([{sensex:{trend:equal,CloseIndexValue: 24893.81,上市前:假,日期时间:上午11:41 AM | 2015年9月8日,CurrentIndexValue:24958.31,段:BSE,OpenIndexValue:24972.01 PercentChange: 0.26, INDEXNAME: SENSEX, NetChange: 64.50}, 极好:{ 趋势: 等于, CloseIndexValue: 7558.80, 盘前 :false,DateTime:11:41 AM | 2015年9月8日,CurrentIndexValue:7582.85,Segment:NSE,OpenIndexValue:7587.70,PercentChange:0.32 ,IndexName:CNX NIFTY,NetChange:24.05},gold:{ClosePrice:26500.00,trend:negative,OpenPrice:26499.00, ExpiryDate:2015-10-05,SpotSymbol:SGOLDAHM,LastTradedPrice:26441.00,DateTime:8-September-2015 11:34:22,符号:GOLD ,PercentChange: -  0.22,CommodityName:Gold,NetChange: -  59.00,PriceQuotationUnit:10 GRMS,SpotPrice:26401.0},silver: {CL osePrice : 35193.00\" , 趋势: 等于, OpenPrice: 35176.00, ExpiryDate: 2015年12月4日, SpotSymbol: SSILVERAHM, LastTradedPrice: 35070.00 ,DateTime:8-September-2015 11:34:0,Symbol:SILVER,PercentChange: -  0.35,CommodityName:Silver,NetChange: -  123.00 ,PriceQuotationUnit:1 KGS,SpotPrice:34815.0},USD / INR:{DateTime:2015-09-08 11:36:02.0,percentChange: - 0.27,netChange: -  0.18,name:USD / INR,bidprice:66.65},DXY Index:{DateTime:2015-09-08 11:39 :40.0,percentChange: -  0.1,netChange: -  0.1,name:DXY Index,bidprice:96.13},marketstatus:{currentMarketStatus:直播}}])


解决方案

返回的数据是 marketlivedata(...)。这是调用 marketlivedata 函数,该函数未在脚本中定义。因为你已经将dataType用作 jsonp ,所以该函数被执行。



要解决此问题,您可以更改来自JSON服务器的数据格式(这可能是不可能的,因为它看起来像第三方服务),或者您可以定义该名称的函数,该函数将在响应到达时被调用。



  function getUserData(){$ .ajax({type:GET,url:http://mobilelivefeeds.indiatimes.com/homepagedatanew.json,dataType:'jsonp', crossDomain:true,success:function(data){// $('#ajexLoaderSec')。hide(); console.log(data);},error:function(e){console.log(e);}} );}; getUserData(); function marketlivedata(data){console.log(data);}  

 < script src =https://ajax.googleapis。 COM / AJAX /库/ jquery的/ 1.11.1 / jquery.min.js>< /脚本>  


HI i have call a json file and show some error can u please help me

show error Uncaught ReferenceError: marketlivedata is not defined

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!DOCTYPE html>
<html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:g="http://base.google.com/ns/1.0">

<head>
  <title>Data Call to json</title>



  <script type="text/javascript">
    // =====================
    $(document).ready(function(e) {
      //    alert('hello');
      //  var marketlivedata ;
    });
     // =====================
    function getUserData() {
      $.ajax({
        type: "GET",
        url: "http://xxxxxxxxx.xxxxxxx.com/xxxxxxx.json",
        dataType: 'jsonp',
        crossDomain: true,
        success: function(data) {
          //  $('#ajexLoaderSec').hide();
          console.log(data);

        },
        error: function(e) {
          alert("There is an error while connecting to the server. Please try after some time");
        }
      });
    };
    getUserData();
  </script>
</head>

<body>
  gsdf sdf sdfsd sdf sd
</body>

</html>

My json format is

marketlivedata([{"sensex":{"trend":"equal","CloseIndexValue":"24893.81","premarket":"false","DateTime":"11:41 AM | 08 Sep 2015","CurrentIndexValue":"24958.31","Segment":"BSE","OpenIndexValue":"24972.01","PercentChange":"0.26","IndexName":"SENSEX","NetChange":"64.50"},"nifty":{"trend":"equal","CloseIndexValue":"7558.80","premarket":"false","DateTime":"11:41 AM | 08 Sep 2015","CurrentIndexValue":"7582.85","Segment":"NSE","OpenIndexValue":"7587.70","PercentChange":"0.32","IndexName":"CNX NIFTY","NetChange":"24.05"},"gold":{"ClosePrice":"26500.00","trend":"negative","OpenPrice":"26499.00","ExpiryDate":"2015-10-05","SpotSymbol":"SGOLDAHM","LastTradedPrice":"26441.00","DateTime":"8-September-2015 11:34:22","Symbol":"GOLD","PercentChange":"-0.22","CommodityName":"Gold","NetChange":"-59.00","PriceQuotationUnit":"10 GRMS ","SpotPrice":"26401.0"},"silver":{"ClosePrice":"35193.00","trend":"equal","OpenPrice":"35176.00","ExpiryDate":"2015-12-04","SpotSymbol":"SSILVERAHM","LastTradedPrice":"35070.00","DateTime":"8-September-2015 11:34:0","Symbol":"SILVER","PercentChange":"-0.35","CommodityName":"Silver","NetChange":"-123.00","PriceQuotationUnit":"1 KGS  ","SpotPrice":"34815.0"},"USD/INR":{"DateTime":"2015-09-08 11:36:02.0","percentChange":"-0.27","netChange":"-0.18","name":"USD/INR","bidprice":"66.65"},"DXY Index":{"DateTime":"2015-09-08 11:39:40.0","percentChange":"-0.1","netChange":"-0.1","name":"DXY Index","bidprice":"96.13"},"marketstatus":{"currentMarketStatus":"Live"}}])

解决方案

The returned data is marketlivedata(...). This is calling the marketlivedata function, which is not defined in your script. Since, you've used dataType as jsonp, the function is executed.

To solve this you can change the data format from the JSON server(which might not be possible as this looks like third party service) or you can define a function of that name which will be called when the response has arrived.

function getUserData() {
  $.ajax({
    type: "GET",
    url: "http://mobilelivefeeds.indiatimes.com/homepagedatanew.json",
    dataType: 'jsonp',
    crossDomain: true,
    success: function(data) {
      //  $('#ajexLoaderSec').hide();
      console.log(data);

    },
    error: function(e) {
      console.log(e);
    }
  });
};
getUserData();


function marketlivedata(data) {
  console.log(data);
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

这篇关于显示一些错误未捕获的ReferenceError:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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