Wednesday, 4 February 2015

error public XML jquery cross domain with php



I need help!! well, the problem is that i can´t receive xml in javascript since php but i don´t know why doesn't work!


First the javascript since call php and send a variable to php





/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

function createObjetXML(url) {
$.ajax({
type: 'GET',
url: url,
dataType: "xml",
success: function (xml) {
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load(xml);
},
error: function () {
alert('Error');
}
});
}

function enviarVariableAxml(valor)
{
var codigoPostal = valor;
codigoPostal = codigoPostal.substring(3);
codigoPostal=parseInt(codigoPostal);

var url = "envioAemet.php?codigoPostal=" + codigoPostal;

$.ajax.open("GET", url, true);
$.ajax.send(null);
createObjetXML(url);
}

function multiPeticion()
{
var now = new Date();
var hora = now.getHours();
var arrayCodigo = ['cod39035', 'cod39075', 'cod39080'];
$.each(arrayCodigo, function (i, valor) {
enviarVariableAxml(valor);


});
}

window.onload = function ()
{
multiPeticion();
};



Second the php since call the public xml





<?php
$codigoPostal=$_REQUEST['codigoPostal'];
$url = $_REQUEST['http://ift.tt/1yJD5rr'+$codigoPostal+'.xml'];
header("Content-type: text/xml");
readfile($url);
?>



thanks!!


No comments:

Post a Comment