Hi,
Well, what I’m trying to do is to get a xml from a webservice.
When the user types a key, buscarCEP() is called and if the field value is a valid address code (xxxxx-xxx), AJAX makes the request to the webservice, but always returns ajax.status == 0 on ajax.readyState == 4.
I found somewhere instruction to use ajax.overrideMimeType(“text/xml”) to specify the request as being for XML.
First, here’s the xml:
[url]http://www.buscarcep.com.br/?cep=60510-430&formato=xml&chave=12A4UYmXG2XVtk/yBh7AEMkc.4xk8y
Please, take a look at my code:
[CODE]function buscaCEP(input,enderecoArr){
var cep = input.value;
var cepRegEx = /^(d{5}-d{3})$/;
var regExp = new RegExp(cepRegEx);
if(regExp.test(cep)) //checks if the entered value is valid
{
var ajax = GetXmlHttpObject();
if(ajax)
{
if(ajax.overrideMimeType)
ajax.overrideMimeType(“text/xml”); //specifies the request for XML
ajax.onreadystatechange = function(){
if(ajax.readyState == 4)
{
if(ajax.status == 200)
{
setaEndereco(ajax.responseXML,enderecoArr);
}
else{
alert(ajax.status);
}
}
}
cep = encodeURIComponent(cep);
var metodo = “GET”;
var url = “http://www.buscarcep.com.br/?cep=”+cep+”&formato=xml&chave=12A4UYmXG2XVtk/yBh7AEMkc.4xk8y.”;
ajax.open(metodo,url,true);
ajax.send(null);
}
}
}
function GetXmlHttpObject(){
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}else if(window.ActiveXObject){
return new ActiveXObject(“Microsoft.XMLHTTP”);
}
return null;
}
I’m out of ideas… is this happening because I’m trying to access a server that’s not my own?
Can anybody help me?
Thanks in advance,
Hênio