Search code examples
jqueryapidatastoreckan

CKAN Basic API jQuery Not Working


Playing around with the CKAN API.

Endpoints all live e.g. http://yuj.it/api/action/datastore_search?resource_id=ed654ac3-2b2b-42f2-bd39-6928cf009c0f

Using jQuery cannot get any results using jQuery AJAX...

What don't I know?

<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<meta charset="utf-8"/>
<title>CKAN API TEST</title>
</head>
<body>
<script>
$(document).ready(function(){
  var data = {resource_id: 'ed654ac3-2b2b-42f2-bd39-6928cf009c0f'};
  $.ajax({
    url: 'http://yuj.it/api/action/datastore_search',
    type: 'POST',
    data: data,
    cache: true,
    dataType: 'jsonp',
    success: function(data) {
      alert('yay');
    },
    error: function(data) {
      alert('boo');
    }
  });
  });
</script>
</body>
</html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
    <meta charset="utf-8"/>
    <title>CKAN API TEST</title>
    </head>
    <body>
    <script>
    $(document).ready(function(){
      var data = {resource_id: 'ed654ac3-2b2b-42f2-bd39-6928cf009c0f'};
      $.ajax({
        url: 'http://yuj.it/api/action/datastore_search',
        type: 'POST',
        data: data,
        cache: true,
        dataType: 'jsonp',
        success: function(data) {
          alert('yay');
        },
        error: function(data) {
          alert('boo');
        }
      });
      });
    </script>
    </body>
    </html>


Solution

  • Today, I tried your code and it works fine "yay" and total results found "69". What have you done on your server ?