From what I observed in your code there is a comma (,
) right after the closure of the success
in your call AJAX, in the code below 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 leave the comma is to call another function or attribute from jQuery AJAX, for example, error
, complete
, follows the example showing that you returned an error message right after the function declaration 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 function error
did not put a comma at the end of the function, this serves for declarations of more attributes or functions that may come last in the AJAX declaration.
EDIT
Based on Sergio’s comment in my answer that the commas do not influence I decided to put the code in Jsfiddle and test, really the problem persisted, so I did 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 I removed the jsonp
and put in place the json
only, but now is returning this error saying that external access is not allowed:
Xmlhttprequest cannot load http://www.revistadostribunais.com.br/maf/api/v1/authenticate.json?sp=ESDEVA-1. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
EDIT
To enable AJAX to access externally, state 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 a 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 your AJAX call:
$.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!'); }
});
to access different domains I cannot use the
dataType: 'json'
, browsers do not allow this type of request– Rafael Cabral
What you can do to access different domains like this is to use a CORS proxy, like http://cors.io/ or http://crossorigin.me/
– Rafael Telles
Leave the
dataType
as'jsonp'
in this case is wrong, jQuery will wait for the call of a function– Rafael Telles
but when using the
'json'
it returns the following error:crossDomain (default: false for same-domain requests, true for cross-domain requests) Type: Boolean If you wish to force a 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)
– Rafael Cabral
And if you use the
json
enablingcrossDomain
how true? I said this when I edited my answer above. If it helps take into consideration to take that -1 of the answer I gave.– Giancarlo Abel Giulian
Do with the example @Rafaeltelles added, tested here and worked with CORS.IO
– Giancarlo Abel Giulian
If we use Cors or crossorigin, it returns success, but the data that comes as success is an error message
"{"error":{"errors":["incorrect_userid"],"localizedErrorMessages":["incorrect_userid"],"firstError":"incorrect_userid"}}
– Rafael Cabral
@Rafaelcabral, you are not passing data along with the request
– Rafael Telles
The requisition is being made successfully, if there is any other problem, I suggest you ask another question, not to pollute this
– Rafael Telles