Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

javascript - Show some error Uncaught ReferenceError:

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...