Invalid JSON issue with malsup Form plugin
I'm having troubles with an existing J2EE application (which uses Dojo) and in which I'm gradually introducing jQuery. The specific issue is with the malsup Form plugin and the JSON returned from a form submission: the error callback is always called, regardless of what happens on the server side, and the error is always "parsererror".
I'm using jQuery 1.4.2 and the 2.45 version of the malsup Form plugin.
For example, given the following code:
-
$(document).ready(function() {
var options = {
dataType: 'json',
success: processAddressEditSubmitSuccess,
error: processAddressEditSubmitError,
beforeSubmit: preEditAddress,
clearForm: true
};
$('#atg_store_editAddress').ajaxForm(options);
// pre-submit hook for address form, stops form submission in case of Cancel button
function preEditAddress (pFormData, pForm, pOptions) {
// look in pForm object to see if the editAddressCancel button has a value: if so, return false from this function, else return true
var cancel = $('#atg_store_editAddressCancel').fieldValue()[0];
if (cancel) {
closeEditAddress();
return false;
}
return true;
}
function processAddressEditSubmitSuccess (pResponse) {
alert('nickname='+pResponse.nickname);
}
function processAddressEditSubmitError (pRequest, pStatus, pErrorText) {
alert('pStatus='+pStatus+'\r\n\r\n'+'pErrorText='+pErrorText);
}
});
the server receives the submission and handles it without errors, then in the browser I always get the same alert from the processAddressEditSubmitError() function, with an "Invalid JSON" message:
- pStatus=parsererror
pErrorText=Invalid JSON: {"nickname":"trytrez","success":"success"}
If I'm doing something wrong, then I'm not seeing what it is. Can anyone help?
Thanks