Search code examples
jqueryajaxjsonjquery-1.5

jquery, problem with ajax call with dataType is json


After upgrading to jQuery 1.5.2 I start to have problems with my ajax calls when returning json data.

The error is (returned by templateGet() below):

Ajax call failed: [object Object] parsererror jQuery152040843801534161517_1302269320612 was not called

Heres a sample return json:

{"subject":"Test subject","body":"Test body"}

And heres the jQuery function

function ajax_templateGet(templateid) {
    showLoading();
    var query = '?action=get_template' + '&templateid=' + templateid;
    $.ajax({
        type: 'POST',
        url: 'script/ajax/mail_template/mail_template.ashx' + query,
        data: '',
        dataType: 'json',
        success: function(data) {
            $("#preview_subject").empty().html(data.subject);
            $("#preview_body").empty().html(data.body);
        },
        error: function(xhr, status, error) {
            $.jGrowl($.i18n._('Ajax call failed: ' + xhr + ' ' + status + " " + error), { header: $.i18n._('Ajax call failed!') });
        },
        complete: function(jqXHR, textStatus) {
            hideLoading();
        }
    });
}

Anyone can see what I do wrong?


Solution

  • Are you using the validation plugin? If so, make sure you get a new copy that's compat with 1.5 - this is a known issue and one that I have had as well.

    https://github.com/jzaefferer/jquery-validation