Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...