首页 > 解决方案 > 错误:Unexpected Token < In Json At Position 0 Cs Cart 提交发布请求时

问题描述

我有一个 Ajax 发布请求,在我提交请求后我收到一个错误:Unexpected token < in JSON at position 0。

如果我使用没有 ajax 的表单,我可以提交表单并在控制器中获取请求。但我想使用 Ajax 请求仅重新加载 id 为“#my_id”的 div。

这是我的要求:

function getData(url, obj) {
  var container = obj.parents('.cm-product-filters');
  var params = {
    method: 'post',
    result_ids: ajax_ids,
    save_history: false,
    caching: false,
    data: {
      is_ajax: true,
      features_hash: generateHash(container),
      security_hash: s_hash
    },
    scroll: '#my_id',
    obj: obj,
    security_hash: s_hash,
    callback: _getDataRespons
    };
    if (ajax_ids) {
       $.ceAjax('request', url, params);
    } else {
       $.redirect(url);
    }

    return false;
}

表格:

<form
  class="cm-ajax cm-product-filters"
  method="post"
  name="form_coffind"
  enctype="multipart/form-data"
  id="gform_5"
  action="{""|fn_url}"
 data-ca-target-id="my_id"
 data-ca-base-url="http://localhost/public_html/cscart?dispatch=pages.view_products"
>
  <input type="hidden" name="result_ids" value="my_id" />
<input type="hidden" name="redirect_url" value="http://localhost/public_html/cscart?dispatch=pages.view_products">
  <div class="gform_body">
    <ul
      id="gform_fields_5"
      class="gform_fields top_label form_sublabel_below description_below"
    >
      <li
        id="field_5_6"
        class="gfield gform_validation_container field_sublabel_below field_description_below"
      >
        <div class="ginput_container">
          <input
            id="button_cart_817"
            class="ty-btn ty-btn__primary cm-submit"
            type="submit"
            name="dispatch[pages.view_products]"
            value="Submit"
          />
        </div>
      </li>
    </ul>
  </div>
</form>
<div class="my_id cm-reload" id="my_id">
<!--my_id--></div>

为什么会出现这个错误?我能做些什么来修复错误?

谢谢。

标签: javascriptphpajaxformcs-cart

解决方案


推荐阅读