1

I need to fetch data from url returned data was JSON.but while trying to fetch i am getting

Uncaught SyntaxError: Unexpected token :

here is the code please check it.

can you please tell me why i am getting this error and how to solve it.

$(document).ready(function () {
  var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE";
    $.ajax({
            contentType: 'application/json',
            dataType: 'json',
            url: Url + '&callback=?',
            success: function (data) {
                alert(data);
            },
            error: function (jqXHR, text, errorThrown) {  }
 });});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

find fiddle link https://jsfiddle.net/vbpradeep/kf9ad1t3/

2 Answers2

0

it seems that you cant build the URL string inside the JSON

instead of creating it in the JSON like this:

url: Url + '&callback=?',

you can just add it to the end of the original URL string:

var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE&callback=?'";

http://codepen.io/nilestanner/pen/pEOgZj

This removes the syntax error although codepen still shows a cross origin error.

Niles Tanner
  • 3,911
  • 2
  • 17
  • 29
  • even though i am getting same error..please check it.please provide fiddle link if it works – Pradeep Kumar Oct 16 '16 at 04:52
  • @PradeepKumar this new error is not the same error that you posted about, We would need more information about the API you are using, and possibly needs to be asked in a separate question. – Niles Tanner Oct 16 '16 at 05:18
0

I hope this solves the issue.

  

      $(document).ready(function() {
        var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE&callback=?";
        $.ajax({
            contentType: 'application/json',
            dataType: 'json',            
            url: Url            
        }).then(function(data){
            //What should happen in success scenarios
            console.log('Success');
            alert(data)
        },function(data){
            //what should happen in failure scenarios
            console.log('Failure Block');
            alert(data)
        });
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Varun G
  • 44
  • 8