2012-01-28 69 views
1

嘿我試圖爲什麼我不斷收到錯誤jQuery和AJAX autorize.net提交

弄清楚這裏是一個錯誤提交表單。請再試一次。 parsererror

試圖提交我的形式authorize.net

authsubmit PHP代碼是這樣的時候:

<?PHP 
require_once 'anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct. 
$transaction = new AuthorizeNetAIM('xxxxxxx', 'xxxxxxx'); 

$post_url = "https://secure.authorize.net/gateway/transact.dll"; 

$transaction->amount  = $_POST['amount']; 
$transaction->card_num  = $_POST['card_num']; 
$transaction->exp_date  = $_POST['exp_date']; 
$transaction->first_name = $_POST['first_name']; 
$transaction->last_name  = $_POST['last_name']; 
$transaction->card_code  = $_POST['cvv']; 
$transaction->address  = $_POST['address']; 
$transaction->city   = $_POST['city']; 
$transaction->state   = $_POST['state']; 
$transaction->zip   = $_POST['zip']; 
$transaction->invoice_num = $_POST['invoice_num']; 
//$transaction->currency_code = $_POST['currency']; 

$response = $transaction->authorizeAndCapture(); 

if ($response->approved) 
{ 
    echo "<h1>Success! The test credit card has been charged!</h1>"; 
    echo "Transaction ID: " . $response->transaction_id; 
} else 
{ 
    echo "here is the error: " . $response->error_message; 
} 
?> 

而且我authsubmit PHP代碼:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 

    $("#frm1").submit(function(){ 

     $.ajax({ 
      type: "POST", 
      url: "authsubmit.php", 
      data: $("#frm1").serialize(), 
      dataType: "json", 

      success: function(msg){ 
       alert("DONE! " + msg); 

      }, 
      error: function(obj, status, e){ 
       alert("There was an error submitting the form. Please try again. " + status); 
      } 
     }); 

     return false; 

    }); 

}); 
</script> 

<html> 
<head> 
</head> 
<body> 

<form id="frm1" method="post"> 
<fieldset> 
    <div> 
     <label>Invoice Amount</label> 
     <input type="text" value="3.33" name="amount" size="15" class="text"> 
    </div> 
    <div> 
     <label>Invoice Number</label> 
     <input type="text" value="23111" name="invoice_num" size="15" class="text"> 
    </div> 
    <div> 
     <label>Credit Card Number</label> 
     <input type="text" value="4500000000009000" name="card_num" size="15" class="text"> 
    </div> 
    <div> 
     <label>Exp.</label> 
     <input type="text" value="1212" name="exp_date" size="4" class="text"> 
    </div> 
    <div> 
     <label>CCV</label> 
     <input type="text" value="782" name="cvv" size="4" class="text"> 
    </div> 
    </fieldset> 
    <fieldset> 
    <div> 
     <label>First Name</label> 
     <input type="text" value="bob" name="first_name" size="15" class="text"> 
    </div> 
    <div> 
     <label>Last Name</label> 
     <input type="text" value="barker" name="last_name" size="14" class="text"> 
    </div> 
    </fieldset> 
    <fieldset> 
    <div> 
     <label>Address</label> 
     <input type="text" value="123 street" name="address" size="26" class="text"> 
    </div> 
    <div> 
     <label>City</label> 
     <input type="text" value="hyyon" name="city" size="15" class="text"> 
    </div> 
    </fieldset> 
    <fieldset> 
    <div> 
     <label>State</label> 
     <input type="text" value="ca" name="state" size="4" class="text"> 
    </div> 
    <div> 
     <label>Zip Code</label> 
     <input type="text" value="45098" name="zip" size="9" class="text"> 
    </div> 
    <div> 
     <label>Country</label> 
     <input type="text" value="US" name="currency" size="22" class="text"> 
    </div> 
    </fieldset> 
    <input type="submit" value="Submit form" /> 
    <div class="form_result"> </div> 
    </form> 
    </body> 
    </html> 

我在這裏錯過了什麼?

大衛

+0

哪裏是你的形式結束?並提交標籤? – 2012-01-28 05:50:00

+0

對不起,它沒有包括在帖子中,但它在那裏。更新了OP。謝謝 – StealthRT 2012-01-28 06:37:27

+0

試試這個:success:function(data){alert(「done」+ data);},failure:function(){alert(「error」);} – 2012-01-28 06:45:12

回答

0

您目前正在使用現場服務器進行測試。這意味着除非您已將您的帳戶設置爲使用測試模式,否則所有交易均爲現場。如果您使用測試信用卡或任何其他無效的信用卡號碼,將導致您收到錯誤消息。

你需要做兩兩件事來有效地測試一個Authorize.Net整合:

  1. 註冊一個developer account。這使您可以測試您的代碼而不會產生任何費用。
  2. 使用開發人員服務器進行測試。

所以:

$post_url = "https://secure.authorize.net/gateway/transact.dll"; 

變爲:

$post_url = "https://test.authorize.net/gateway/transact.dll";