为什么Mootools的新Request类什么都不做......或者忽略了我?

时间:2011-12-19 20:01:17

标签: javascript joomla mootools

我正在为Joomla 1.7开发组件,Joomla 1.7与Mootools 1.3一起使用。在此之前,mootools的正确方法是Ajax类。但在Mootools中,正如我所读,我必须使用Request class。

好的,当我尝试使用Request类并看看Google Inspector逐步调试请求定义和请求send()调用。我可以看到,它执行send但它什么都不做(忽略onSuccess,忽略OnException等)。

如果我查看chrome javascript控制台,那就什么都没有了。

function addValue(value) {
    var id = $('selectedval').getProperty('value');
    var url = 'index.php?option=com_kaltura&controller=fieldsmanager&task=additem&tmpl=component';
    var req = new Request(url, {
        method: 'post',
        data: {
            'id': id,
            'value': value
        },
        onRequest: function(event, xhr) {alert('gogogo'); },
        onFailure: function(xhr) { alert('failure'.xhr); },
        onException: function(test) {alert(test); },
        onSuccess: function(data) {
            loadFieldList(data);
        }
    });
    req.send();
}

1 个答案:

答案 0 :(得分:1)

api已从1.1x变为1.2 - >请求现在接受一个参数对象,该对象重载您需要的所有选项,包含url - 之前曾是参数[0]。

换句话说 - 将url从那里移动到options对象的属性中:

new Request({
    url: url,
    method: 'post',
    data: {
        'id': id,
        'value': value
    },
    onRequest: function(event, xhr) {alert('gogogo'); },
    onFailure: function(xhr) { alert('failure'.xhr); },
    onException: function(test) {alert(test); },
    onSuccess: function(data) {
        loadFieldList(data);
    }
}).send();
相关问题