1
I am creating a stock input/output system using an XML file
For this, I need to create a preview of the XML content that the user is uploading (as a table, just for the person to know if it is that XML even)
I am developing in Codeigniter, the receipt of XML by the controller is like this:
public function recebeXML(){
$arquivo = $_FILES['arquivo'];
$xml = simplexml_load_file($arquivo['tmp_name']);
$numProdutos = count(/*numero de produtos*/);
for($i = 0; $i<$numProdutos; $i++){
$produto = $xml->NFe->det[$i]->prod;
$dados[$i] = array(
"CodigoProduto" => (string)$produto->cProd,
"NomeProduto" => (string)$produto->xProd,
"Quantidade" => (string)$produto->uCom,
);
}
}
$this->entradaDados($dados);
}
The data is placed in the table through a foreach.
The question itself is : is there any way to put organized data into the user’s view without having to reload the page? I thought of creating a modal to appear after I uploaded, but how to put the files inside?
You wanted something with Ajax, without refreshing the page? IE, this code already works, but, you want to do with a better interaction?
– novic
Exactly that, I just don’t know how to proceed with it
– Walter Felipe
Have to do a post with ajax passing the XML file as you already do traditionally and in the response of ajax rescue this data and show in a table, for example with Angular would be easy to mount this, but, are steps to be followed.
– novic
Do you know of any site or forum that detail more how to do this? I know absolutely nothing about AJAX
– Walter Felipe
Here on the site there is a lot of link about ajax (https://answall.com/questions/tagged/ajax) just give a read, I can even put together a minimum example who knows if you can use as an example and pass it to your code.
– novic
Could be, would help a lot!
– Walter Felipe