有没有办法使用prototypejs从文本文件中读取数据?

时间:2014-05-20 03:29:19

标签: javascript prototypejs

我正在编写测试,并希望prototypejs从文本文件中读取并存储变量。这有可能,我做错了什么?

Selenium.prototype.doLoadData = function(dataFile) {

    new Ajax.Request('dataFile', {
      method:'get',
      onSuccess: function(data) {
        var lines = data.split("\n");
        lines.each(lines, function(i) {
            var line = lines[i].split(' = ');
            window[line[0]] = line[1];

            globalStoredVars[line[0]] = line[1];
            });
            }
    }
);
};

1 个答案:

答案 0 :(得分:1)

PrototypeJS将AJAXTransport对象传递给成功回调,而不仅仅是数据。试试这个

onSuccess: function(resp){
    var data = resp.responseText;
    //or if your response contains JSON
    //and the Content-Type: application/json header was sent in the response
    var data = resp.responseJSON;
}