如何在每次对服务器的XML调用之后更新html表而不刷新页面?


How do I update an html table after each XML call to the server without refreshing the page?

我有一个加载了50行的mySQL表。每一行都包含处理信用卡所需的信息。当用户单击Process Credit Cards时,查询该表并使用html在页面上显示每一行。一旦数据显示在页面上,脚本将开始通过商家帐户处理每一行,并将相应的行变为红色表示拒绝或绿色表示批准,而无需在每次交易后刷新页面。我认为我需要使用AJAX或jQuery来实现这一点,但我不确定我是否朝着正确的方向前进。下面是处理事务的脚本:

<?php
$request = new GatewayRequest();
$response = new GatewayResponse();
$service = new GatewayService();

$request->Set(GatewayRequest::MERCHANT_ID(), "111111111111111");
$request->Set(GatewayRequest::MERCHANT_PASSWORD(), "xxxxxxxxxxxx");

$time = time();
$request->Set(GatewayRequest::MERCHANT_CUSTOMER_ID(), $time . '.PHPTest');
$request->Set(GatewayRequest::MERCHANT_INVOICE_ID(), $time . '.SaleTest');

$request->Set(GatewayRequest::AMOUNT(), "9.99");
$request->Set(GatewayRequest::CARDNO(), "4111111111111111");
$request->Set(GatewayRequest::EXPIRE_MONTH(), "02");
$request->Set(GatewayRequest::EXPIRE_YEAR(), "2010");
$request->Set(GatewayRequest::CVV2(), "999");

$request->Set(GatewayRequest::CUSTOMER_FIRSTNAME(), "Joe");
$request->Set(GatewayRequest::CUSTOMER_LASTNAME(), "PHPTester");
$request->Set(GatewayRequest::EMAIL(), "phptest@fakedomain.com");
$request->Set(GatewayRequest::IPADDRESS(), $_SERVER['REMOTE_ADDR']);

$request->Set(GatewayRequest::BILLING_ADDRESS(), "123 Main St");
$request->Set(GatewayRequest::BILLING_CITY(), "Las Vegas");
$request->Set(GatewayRequest::BILLING_STATE(), "NV");
$request->Set(GatewayRequest::BILLING_ZIPCODE(), "89141");
$request->Set(GatewayRequest::BILLING_COUNTRY(), "US");


$request->Set(GatewayRequest::SCRUB(), "IGNORE");
$request->Set(GatewayRequest::CVV2_CHECK(), "IGNORE");
$request->Set(GatewayRequest::AVS_CHECK(), "IGNORE");
$service->SetTestMode(TRUE);
if ($service->PerformPurchase($request, $response)) {
  print "Purchase succeeded'n";
  print "Response Code: " .
    $response->Get(GatewayResponse::RESPONSE_CODE()) . "'n";
  print "Reasone Code: " .
    $response->Get(GatewayResponse::REASON_CODE()) . "'n";
  print "Auth No: " . $response->Get(GatewayResponse::AUTH_NO()) . "'n";
  print "AVS: " . $response->Get(GatewayResponse::AVS_RESPONSE()) . "'n";
  print "CVV2: " . $response->Get(GatewayResponse::CVV2_CODE()) . "'n";
  print "GUID: " . $response->Get(GatewayResponse::TRANSACT_ID()) . "'n";
  print "Account: " .
    $response->Get(GatewayResponse::MERCHANT_ACCOUNT()) . "'n";
  print "Scrub: " .
    $response->Get(GatewayResponse::SCRUB_RESULTS()) . "'n";
} else {
  print "Purchase failed'n";
  print "GUID: " . $response->Get(GatewayResponse::TRANSACT_ID()) . "'n";
  print "Response Code: " .
    $response->Get(GatewayResponse::RESPONSE_CODE()) . "'n";
  print "Reasone Code: " .
    $response->Get(GatewayResponse::REASON_CODE()) . "'n";
  print "Exception: " .
    $response->Get(GatewayResponse::EXCEPTION()) . "'n";
  print "Scrub: " .
    $response->Get(GatewayResponse::SCRUB_RESULTS()) . "'n";
}
?>

这种类型的代码将工作与AJAX或jQuery不重写吗?

任何东西都可以在不重写的情况下工作,但是您已经为自己设置了许多令人头痛的问题。通过将所有这些print语句格式化成一个数组并使用JSON对其进行编码,您可能会有更好的运气(并节省大量时间)。显然javascript喜欢JSON。