I have an Ajax post request, and after I submit the request I get an error: Unexpected token < in JSON at position 0.
If i use the form without ajax I can submit the form and get the request in the controller. But i want to use the Ajax request to reload only the div with the id '#my_id'.
Here is my request:
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;
}
The Form:
<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>
Why this error occurs? What can I do to fix the error?
Thanks.