1
I want to do a function that the customer type his order 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, someone would know how to do?
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 don’t know where, but I think I’m doing some wrong check on IF.
jQuery Ajax try
$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!");
}
},
})
});