jquery ajax 200 parsererror,Ajax error: 200 parsererror

博客内容讲述了在使用jQuery Validation Engine插件进行AJAX表单验证时遇到的问题,包括验证回调函数的错误处理和JSON响应的期望格式。作者发现问题并非插件引起,而是需要编写一个PHP文件来处理AJAX验证的响应,当验证成功后,进一步处理表单数据。博客提到了在验证完成后的处理步骤,并指出文档对此部分的说明不够清晰。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Of course I did. This is my code for that.

function beforeCall(form, options){

if (window.console)

// console.log("Right before the AJAX form validation call");

return true;

}

// Called once the server replies to the ajax form validation request

// function ajaxValidationCallback(status, form, errors, options){

function ajaxValidationCallback(form, status){

if (window.console)

console.log(status);

if (status === true) {

alert("the form is valid!");

// uncomment these lines to submit the form to form.action

form.validationEngine('detach');

//form.submit();

}

}

jQuery('#appForm').validationEngine('attach', {

validationEventTrigger:"focusout",

relative:true,

ajaxFormValidation:true,

// onAjaxFormComplete: ajaxValidationCallback,

onValidationComplete: ajaxValidationCallback,

onBeforeAjaxFormValidation: beforeCall

});

It doesn't even scroll up anymore to the first error, so it's possible that there's something wrong in my code, but I don't see how that would break the json data. Especially if it looks like it's being sent fine. Is it an issue with jQuery 1.7.1?

ETA: Well, it wasn't an issue with the plugin. My bad. I finally loaded up Firefox to check it in Firebug and saw the php response.

Sorry for wasting your time!

ETA2: In case anyone else has this issue (which is probably going to be me again lol), _validateFormWithAjax is expecting a json response from the server. So to actually use _validateFormWithAjax via onAjaxFormComplete or onValidationComplete, you're going to have to write a PHP file for AJAX form validation (see demos/phpajax/ajaxValidateSubmit.php), and, when that is successful, do whatever processing you want your form data to do.

In my case, the processing is converting all the data to a human readable text output for an email body, which will be done via a jQuery ajax call after _validateFormWithAjax returns true.

Hope that helps someone else! The docs are so not clear about form submit.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值