I noticed in your code that there is a comma ( ,
) shortly after closing success
in your AJAX call, in the code below I removed the comma, note:
$.ajax({
type: 'GET',
url: 'http://www.revistadostribunais.com.br/maf/api/v1/authenticate.json?sp=ESDEVA-1',
dataType: 'jsonp',
success: function() { console.log('Success!'); }
});
What you could do to drop the comma is to call another jQuery AJAX function or attribute, such as error
, complete
, follow the example showing that you returned an error message shortly after the declaration of function sucess
:
$.ajax({
type: 'GET',
url: 'http://www.revistadostribunais.com.br/maf/api/v1/authenticate.json?sp=ESDEVA-1',
dataType: 'jsonp',
success: function() {
console.log('Success!');
}, error: function(e){
alert('Ocorreu um erro durante a chamada ' + e);
}
});
Note that after closing the error
function, I did not put a comma at the end of the function, this is used for declarations of the most attributes or functions that may come last in the AJAX declaration.
EDIT
Based on Sergio's comment in my reply that the commas do not influence I decided to put the code in JSFiddle and test, the problem really persisted, so I made the following code snippet:
$.ajax({
type: 'GET',
url: 'http://www.revistadostribunais.com.br/maf/api/v1/authenticate.json?sp=ESDEVA-1',
dataType: 'json',
success: function() { console.log('Success!'); }
});
Notice that I removed the jsonp
and put the json
in place only, but is now returning this error saying that external access is not allowed:
XMLHttpRequest can not load link . In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access.
EDIT
To enable AJAX to access externally, declare this in your AJAX:
crossDomain: true,
Documentation:
CrossDomain (default: false for same-domain requests, true for cross-domain requests)
Type: Boolean
If you wish to force crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain. (version added: 1.5)
EDIT
Example of what your AJAX call would look like:
$.ajax({
type: 'GET',
url: 'http://www.revistadostribunais.com.br/maf/api/v1/authenticate.json?sp=ESDEVA-1',
crossDomain: true,
dataType: 'json',
success: function() { console.log('Success!'); }
});