2
I have a call ajax
that falls in the callback
error and brings me a status 200
and statusText load
.
Follow the ajax:
$.ajax({
type: "GET",
crossDomain: "true",
dataType: "jsonp",
contentType: "text/xml",
url: "http://macchips.macpontoweb.com.br/WSVisita/Services/Comum/Autenticacao/AutenticacaoSrv.svc?Login",
data: 'usuario='+usuario.value+'&senha='+senha.value,
success: function(resposta){
window.location.href="login.html";
alert(resposta);
},
error: function(error){
var falha = JSON.stringify(error);
alert("Erro " + falha);
}
});
I am trying to access a method of a webservice from another domain via a mobile application, using Cordova
As I recall, ajax requests can only be made from a domain to itself, unless that server is configured to accept ajax calls from "external" sources; I may be mistaken... Whoever provided you with this webservice did not demonstrate how to use it?
– Rafael Withoeft
Why did you define 'dataType' and 'contenttype'? This does not cause any setbacks?
– Jhonny Mesquita
@Jhonnyjks Contenttype is what you send to the server, and datatype is what the server returns. You can set the two in a request
– CBredlow
Ops, I was confusing with the Contenttype of the answer, q is ignored when we set dataType...
– Jhonny Mesquita
What would be the value of the parameter "? Login". Otherwise, tried to verify which would be the correct parameters to be passed, not the values?
– Matheus
Prametro login is going vázio, the dataType, when changed to "json" returns status 0 and not 200. I think you need to check properly the parameters that will be sent to this WS. Make sure the CORS are enabled.
– Duque
The Login parameter asks for a user and a password. CORS are enabled. If I take contenttype or dataType, the code does not work either
– Gabriel Donato
Caro @Gabrieldonato even if in the json body the status is 200, probably the status returned by the server and this header of the Sponse is other than 200.
– heat
@Gabrieldonato I think CORS errors, can return 200 even... To remove the doubt put complete: Function(xhr, textStatus) { console.log(xhr.status); } in Ajax. CORS may require special headers sent in the request, take a look if this is not the case, even on servers configured for "*" domain. The browser itself can prevent a request to another domain by ajax if it does not have the headers... You should usually pass the "Origin" header with your -> Origin: http://foo.com domain
– repeatdomiau