$.ajax to $getJSON

$.ajax to $getJSON

本文关键字:getJSON ajax to      更新时间:2023-09-26

我想将以下Jquery代码转换为使用$。Ajax代替$。getJSON,将是$。Ajax代码?

$(function () {
    $('#checkExists').click(function () {
     $.getJSON($(this).attr('href'), function (result) {
            alert(result);
            if (result) {
                alert('the record exists');
            }           
        });
        return false;
    });
});

请建议

$.ajax({
  url: $(this).attr('href'),
  success: function (result) { ... },
  dataType: 'json'
});

另外,我建议使用event.preventDefault()而不是return false;