Difficulty with Ajax Jsonp

0

I'm trying to consume an api through Ajax, but I get an error executing it.

var data2 = {
    resource_id: '1d7e45e5-b159-46a2-bdce-90393c7a8a2b', // the resource id
    limit: 5, // get 5 results
    q: 'jones', // query for 'jones'      
};
$.ajax({
    url: 'https://demo.ckan.org/api/3/action/datastore_search',
    data: data2,       
    dataType: 'jsonp',
    success: function (data2)
    {
        debugger;
        alert('Total results found: ' + data2.result.total)
    }
});

In the browser console I noticed that it adds two parameters that I did not pass: callback=jQuery21409543886738626624_1528899809074 e &_=1528899809075

URL that appears in the console:

https://demo.ckan.org/api/3/action/datastore_search?callback=jQuery21409543886738626624_1528899809074&resource_id=1d7e45e5-b159-46a2-bdce-90393c7a8a2b&limit=5&q=jones&_=1528899809075

How should it be:

https://demo.ckan.org/api/3/action/datastore_search?resource_id=1d7e45e5-b159-46a2-bdce-90393c7a8a2b&limit=5&q=jones 
    
asked by anonymous 13.06.2018 / 16:31

1 answer

0

In your Ajax include cache: true see here why

  

In the browser console I noticed that it adds two parameters that I did not pass: callback = jQuery21409543886738626624_1528899809074 and & _ = 1528899809075

var data2 = {
  resource_id: '1d7e45e5-b159-46a2-bdce-90393c7a8a2b', 
  limit: 5,
  q: 'jones',    
};
$.ajax({
  url: 'https://demo.ckan.org/api/3/action/datastore_search',
  data: data2,
  dataType: 'jsonp',
  cache: true,
  success: function(result) {
    alert('Resultados encontrados: ' + result.result.total)
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
13.06.2018 / 18:18