简体   繁体   English

如何调试ajax脚本

[英]How to debug a ajax script

I try to find why something doesn't in my script我试图找出为什么我的脚本中没有某些内容

My problem is in discount_code .我的问题是在discount_code I try to see if there is something or not and if the data is ok, but I don' see nothing.我试着看看是否有东西,数据是否正常,但我什么也没看到。

How to see for example $sess_discount_code or all data that I want in discount_code.php to try to debug the file ?如何查看例如$sess_discount_code或我想要在discount_code.php中尝试调试文件的所有数据?

Thank you谢谢

In my shopping_cart.php , I have that在我的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

In my discount_code.php , I have that :在我的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;

There exists chuncks of tools to do such tasks, such as Finddler or Charles .存在大量工具来执行此类任务,例如FinddlerCharles You can use them to watch HTTP requests and response including ajax.您可以使用它们来观察 HTTP 请求和响应,包括 ajax。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM