How do I receive a JSON file using AJAX and parse it using javascript?

前端 未结 3 1963
深忆病人
深忆病人 2021-01-07 14:13

I\'m trying to parse this very long and complicated JSON that foursquare gives me. This is my AJAX request:

    $.ajax({
      url: \'https://api.foursquare.         


        
3条回答
  •  暖寄归人
    2021-01-07 14:52

    The success property of the object in your ajax call just needs function name or an function object. You either give it just the name, like that:

        $.ajax({
          url: 'https://api.foursquare.com/v2/venues/explore',
          dataType: 'json',
          data: 'limit=7&ll='+latitude+','+longitude+'&client_id='+client_id+'&client_secret='+client_secret+'',
          async: false,
          success: getVenues
    });
    

    or you do this:

      $.ajax({
          url: 'https://api.foursquare.com/v2/venues/explore',
          dataType: 'json',
          data: 'limit=7&ll='+latitude+','+longitude+'&client_id='+client_id+'&client_secret='+client_secret+'',
          async: false,
          success: function(data) { getVenues(data) }
    });
    

提交回复
热议问题