Error, status 200 load Ajax

Asked

Viewed 261 times

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?

  • Why did you define 'dataType' and 'contenttype'? This does not cause any setbacks?

  • @Jhonnyjks Contenttype is what you send to the server, and datatype is what the server returns. You can set the two in a request

  • Ops, I was confusing with the Contenttype of the answer, q is ignored when we set dataType...

  • 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?

  • 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.

  • 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

  • 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.

  • @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

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.