简体   繁体   中英

REST API call not working

I have tried to use both .ajax and .getJSON, but neither methods have worked. I am using the goodzer rest api.

Code:

$(document).ready(function(){
  $( "#click" ).click(function() {
  $.ajax({url: "https://api.goodzer.com/products/v0.1/search_stores/?query=v-neck+sweater&lat=40.714353&lng=-74.005973&radius=5&priceRange=30:120&apiKey=APIKEY", success: function(result){
        console.log(JSON.stringify(result));
                }});
        });
    });
$.ajax({
    url: 'https://api.goodzer.com/products/v0.1/search_stores/?query=v-neck+sweater&lat=40.714353&lng=-74.005973&radius=5&priceRange=30:120&apiKey=APIKEY',
    type: 'GET',
    success: function() { alert('get completed'); }
});

I just had to switch the code to

$(document).ready(function(){
  $( "#click" ).click(function() {
  $.getJSON("https://api.goodzer.com/products/v0.1/search_stores/?query=v-neck+sweater&lat=40.714353&lng=-74.005973&radius=5&priceRange=30:120&apiKey=API-KEY", function(result){
        alert(result.stores_found);
                });
        });
    });

And codePen for some reason did not allow this code to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM