0
function updateRecord(actdate, plandate, bugnumber) {
    var adate = document.getElementById(actdate).value.split("-");
    var pdate = document.getElementById(plandate).value.split("-");
            jQuery.ajax({
                url: '?=bug_parser/updaterecord/'+adate[0]+'/'+adate[1]+'/'+adate[2]+'/'+pdate[0]+'/'+pdate[1]+'/'+pdate[2]+'/'+bugnumber,
                dataType: 'html',
                async:true,
                crossDomain:true,
                success: function(response, textStatus, jqXHR) {
                    if(response == '1') {
                        alert("success");
                    } else {
                        alert("Failed");
                    }       
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    alert('Error updating the record');
                },
            });
    return false;
} 

我正在尝试通过按钮单击事件上的 ajax 调用来更新记录。在我的 drupal 模块中有适当的菜单回调。有趣的是,如果我将 url 复制粘贴到浏览器导航栏中,它会按预期工作。但是,如果我通过 javascript 进行 ajax 调用,它就不起作用

4

1 回答 1

0

您的 ajax 无法正常工作的原因是您需要将其放入 drupal 行为中。

查找 drupal js 行为。它基本上是为您的 js 创建一个包装器,因此它适用于 drupal javascript 文件和包含。

您还可以将此主题用作行为的参考:Drupal 行为

通常你所有的javascript都必须进入一个行为。这是最佳实践,可以为您省去很多麻烦

于 2012-11-30T13:54:44.443 回答