0

Is it returning me error 500 syntax, does anyone see any errors?

jQuery Code

            var ordertxt = $j("#ordertxt"); 
                ordertxt.blur(function() { 
                    $j.ajax({ 
                        url: '<?php echo Mage::getUrl('contato/index/verifica') ?>', 
                        type: 'POST', 
                        data:{"ordertxt" : ordertxt.val()}, 
                        success: function(data) { 
                        console.log(data); 
                        data = $j.parseJSON(data); 
                        $j("#msg_pedido").text(data.ordertxt);
                    } 
                }); 
            });

Controller Action

    public function verificaAction() {

            if(isset($_POST['ordertxt'])){ 

            //Recebe o Email Postado
            $ordertxt = $_POST['ordertxt'];

            //Conecta banco de dados 
            $sql = Mage::getModel('sales/order')->loadByIncrementId($ordertxt) or print mysql_error();

            //Se o retorno for maior do que zero, diz que já existe um.
            if ($sql[0]['increment_id'] == $ordertxt) {
                echo json_encode(array('ordertxt' => 'Pedido Valido')); 
            }else{ 
                echo json_encode(array('ordertxt' => 'Pedido Invalido.' )); 
            }
        }
}
4
  • do you get $ordertxt in your controller? Commented Aug 23, 2017 at 17:30
  • Yes, by getPost Commented Aug 23, 2017 at 17:31
  • do you get increment id $ordertexto[0]['increment_id'] here? Commented Aug 23, 2017 at 17:33
  • Yes, I look at the table by Mage :: getModel Commented Aug 23, 2017 at 17:35

3 Answers 3

0

Instead of loading all the orders and then filter one. Load Particular one

 $order = Mage::getModel('sales/order')->loadByIncrementId($ordertxt);
4
  • I edited the question because I edited my code with what you gave me, I believe it is an error in the comparison logic or in the sql connection, It returns me, but even if the request is valid it only returns the else Commented Aug 23, 2017 at 18:10
  • If it has no value, it's valid request, if it has any value it invalid. Commented Aug 23, 2017 at 18:13
  • what will you get $sql[0]['increment_id'] in this variable? Commented Aug 23, 2017 at 18:16
  • here $sql = Mage::getModel('sales/order')->loadByIncrementId($ordertxt) or print mysql_error(); Commented Aug 23, 2017 at 18:19
0

Solution:

jQuery

            var ordertxt = $j("#ordertxt"); 
                ordertxt.blur(function() { 
                    $j.ajax({ 
                        url: '<?php echo Mage::getUrl('contato/index/verifica') ?>', 
                        type: 'POST', 
                        data:{"ordertxt" : ordertxt.val()}, 
                        success: function(data) { 
                        console.log(data); 
                        data = $j.parseJSON(data); 
                        $j("#msg_pedido").text(data.ordertxt);
                    } 
                }); 
            });

Action

    public function verificaAction() {

                if(isset($_POST['ordertxt'])){ 

                $ordertxt = $_POST['ordertxt'];


                $sql = Mage::getModel('sales/order')->loadByIncrementId($ordertxt);


                if($sql->getIncrementId()){
                    echo json_encode(array('ordertxt' => 'Pedido valido')); 
                }
                else  {
                    echo json_encode(array('ordertxt' => 'Pedido Inválido.' )); 
                }
            }
        }
0

I am assuming you get an apache 500 error when you are saying "Is it returning me error 500 syntax"? If so this is an apache internal server error. Check your websevers logs first to get a clue what is going wrong.

This will give you a good clue on where to look before diving deep into your code. Solve the 500 internal server error first and then dive back into your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.