首页 > 解决方案 > 我有一个提交给自身的表单,导致页面刷新。我正在尝试使该代码进行 ajax 调用,因此只有一些页面刷新

问题描述

此代码将购物车的信息提交给它自己。刷新整个页面,但更新可用性和数量等值。(不包括一些代码)我试图让它成为一个类似于位于下面的代码的 ajax 调用。

<form action="${URLUtils.httpsContinue()}" method="post" name="${pdict.CurrentForms.cart.htmlName}" id="cart-items-form">
  <fieldset>
    <legend class="visually-hidden">Your cart</legend>
    <iscomment>This button is hidden but required to ensure that update cart is called whenever the "enter" key is pressed in an input field</iscomment>
    <button class="visually-hidden" type="submit" value="${pdict.CurrentForms.cart.updateCart.htmlName}" name="${pdict.CurrentForms.cart.updateCart.htmlName}"></button>
    <table id="cart-table" class="item-list">
      <thead>
        <tr>
          <th class="section-header" colspan="2">${Resource.msg('global.product','locale',null)}</th>
          <isif condition="${dw.system.Site.getCurrent().getCustomPreferenceValue('enableStorePickUp')}">
            <th class="section-header">${Resource.msg('cart.store.deliveryoptions','storepickup',null)}</th>
          </isif>
          <th class="section-header quantity" colspan="2">${Resource.msg('global.qty','locale',null)}</th>
          <th class="section-header price">${Resource.msg('global.price','locale',null)}</th>
          <th class="section-header header-total-price">${Resource.msg('global.totalprice','locale',null)}</th>
        </tr>
      </thead>

      <tbody>

        <iscomment> LOOP TO SEPARATE DIFFERENT SHIPMENTS ex: Gift Registry Shipments Etc.</iscomment>
        <isloop items="${pdict.CurrentForms.cart.shipments}" var="Shipment" status="loopstate">
          <isloop items="${Shipment.items}" alias="FormLi" status="loopstate">
            <isset name="lineItem" value="${FormLi.object}" scope="page" />
            <isscript>
              var isInWishList = false; if (pdict.WishList) { var wishListItems = pdict.WishList.items; var wishListItemsSize = wishListItems.size(); for each( var wishListItem in wishListItems ) { if (lineItem.productID == wishListItem.product.ID) { isInWishList =
              true; break; } } }
            </isscript>

            <iscomment> Skip bonus-choice products in first pass. </iscomment>
            <isif condition="${lineItem.bonusDiscountLineItem == null && (lineItem.productID == null || lineItem.productID != ptimeHelper.getNextDayProductID()) && !lineItem.custom.upsellItem}">
              <tr class="cart-row" data-uuid="${lineItem.getUUID()}">
                <td class="item-image">
                  <isset name="image" value="${new ProductImage('small', lineItem.product, 0)}" scope="page" />
                  <isif condition="${lineItem.product != null && image != null}">


</form>

我需要这样的 ajax 调用:有什么建议吗?我可以将其从表单中取出并以另一种方式存储数据吗?

progress.show($('.search-result-items'));
refineUrl = refineUrl.replace('?', '?format=ajax&');
$('#main').load(refineUrl, function () {
    compareWidget.init();
    productTile.init();
    progress.hide();

标签: javascriptajaxsalesforcesalesforce-communities

解决方案


推荐阅读