I want to make a function that the customer type his request it is checked if it exists in the bank or if it is an invalid request. And I want to return this via Ajax, but I never messed with Ajax, would anyone know how to do it?
Function
public function verificaAction() {
#Recebe o Pedido Postado
$increment_id = $this->getRequest()->getParam('ordertxt');
#Conecta banco de dados
$ordertexto = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('increment_id', $increment_id);
#Se o retorno for maior do que zero, envia o form, se for menor da o error
if ($ordertexto[0]['increment_id'] == $increment_id) {
} else {
echo json_encode(array('increment_id' => 'Número invalido' ));
}
}
I do not know where, but I think I'm doing some erroneous verification in the IF.
jQuery Ajax attempt
$j("#ordertxt").focus(function() {}).blur(function() {
ordertxt = $j("#ordertxt").val();
$j.ajax({
url: '<?php echo Mage::getUrl('contato/index/verifica') ?>',
type: 'POST',
dataType: "json",
success: function () {
if (ordertexto == 1) {
$j("#msg_pedido").html("Esse número de pedido não existe!");
} else if (ordertexto == 0) {
$j("#msg_pedido").html("Esse existe!");
}
},
})
});