如何调试ajax脚本

时间:2015-07-01 03:03:41

标签: php ajax

我试着找出为什么我的剧本中没有东西

我的问题出在discount_code。我试着看看是否有什么东西,如果数据没问题,但是我不知道。什么也看不见。

如何在$sess_discount_code中查看discount_code.php或我想要的所有数据来尝试调试文件?

谢谢

在我的shopping_cart.php中,我有

if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true') {
  global $sess_discount_code;
  $footer .= '
  $(document).ready(function() {
    var a = 0;
    discount_code_process();
    $(\'#inputCoupon\').blur(function() { if (a == 0) discount_code_process(); a = 0 });
    $("#inputCoupon").keypress(function(event) { if (event.which == 13) { event.preventDefault(); a = 1; discount_code_process() } });
    function discount_code_process() { if ($("#inputCoupon").val() != "") { $("#inputCoupon").attr("readonly", "readonly"); $("#discount_code_status").empty().append(\'<i class="fa fa-cog fa-spin fa-lg">&nbsp;</i>\'); $.post("discount_code.php", { inputCoupon: $("#inputCoupon").val() }, function(data) { data == 1 ? $("#discount_code_status").empty().append(\'<i class="fa fa-check fa-lg" style="color:#00b100;"></i>\') : $("#discount_code_status").empty().append(\'<i class="fa fa-ban fa-lg" style="color:#ff2800;"></i>\'); $("#inputCoupon").removeAttr("readonly") }); } } });
  ';
}

$footer .= '
</script>
<!-- End shipping estimator -->
';



// Discount Code - start
          if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true') {
            if ($sess_discount_code == 'undefined') $sess_discount_code = '';


            $discounttxt = '<div class="col-sm-12 row">';

            if ($OSCOM_Customer->isLoggedOn()) {

              $discounttxt .= '<div class="col-sm-12"><strong>' . MODULE_SHOPPING_CART_SHIPPING_ESTIMATOR_DISCOUNT_CODE_TITLE . '</strong></div>
                               <div class="col-sm-5">' . HTML::inputField('coupon', $sess_discount_code, 'id="inputCoupon"') . '<span id="discount_code_status"></span></div>

                               <div class="col-sm-6"><a class="btn btn-default" role="button" href="_" onclick="return shipincart_submit(\'\');"><i class="glyphicon glyphicon-refresh"></i>&nbsp;'. IMAGE_BUTTON_UPDATE . ' </a></div>';
            } else {

              $discounttxt .= '<div class="col-sm-12">' . MODULE_SHOPPING_CART_SHIPPING_ESTIMATOR_DISCOUNT_CODE_TEXT_LOG_IN . '</div>
                               <div class="col-sm-12">' . HTML::button(MODULE_SHOPPING_CART_SHIPPING_ESTIMATOR_BUTTON_LOGIN, 'glyphicon glyphicon-log-in', OSCOM::link('login.php'), 'btn-success btn-sm') . '</div>';
            }

            $discounttxt .= '</div>
                          <div class="hr"></div>
                          <div class="clearfix"></div>
                          <div class="hr"></div>
                          ';
            $ShipTxt .= $discounttxt;
          }
// Discount Code - end

在我的discount_code.php中,我有:

  $discount = 0;

  var_dump($sess_discount_code); ===> How to see that ????

  if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true' && !empty($_SERVERS['HTTP_X_REQUESTED_WITH']) && $SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {

    ................


 }

  register_shutdown_function('session_write_close');

  echo $discount > 0 ? 1 : 0;

  exit;

1 个答案:

答案 0 :(得分:0)

有很多工具可以执行此类任务,例如 Finddler Charles 。您可以使用它们来监视HTTP请求和响应,包括ajax。