将数据保存到本地文本文件

时间:2015-06-28 18:06:09

标签: javascript jquery

// Queries atlatlsoftware.com and returns the site in json data format, using YQL
$.ajax({
    url: "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fatlatlsoftware.com%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2F*%5B%40id%3D%22desktop-footer%22%5D%2Fdiv%5B3%5D%2Fdiv%2Ftable%2Ftbody%2Ftr%5B2%5D%2Ftd%5B1%5D'&format=json&diagnostics=true&callback=?",
    dataType: 'jsonp',
    // upon success, logs the data as "response"
    success: function (response) {

        // simply following the json data path and assigning it to a variable
        var address = response.query.results.td.div[1].content;
        var phone = response.query.results.td.div[2];
        var email = response.query.results.td.div[3];
        // var tweet = response.query.results;

        // appends the variable to the html
        $(".address").html(address);
        $(".phone").html(phone);
        $(".email").html(email);
        console.log(address);
        console.log(phone);
        console.log(email);
        // console.log(tweet);

    }
});

上面的脚本从网站上提取地址,电子邮件和电话号码。我怎样才能简单地将这些数据保存到文本文件中?

我尝试this但没有使用点击事件

1 个答案:

答案 0 :(得分:0)

据我所知,Firefox和Chrome都不要求在链接文章的saveTextAsFile中运行代码以响应用户事件。 (这是可怕的,几乎肯定是一个错误。)所以只需调整示例,以便从saveTextAsFile完成处理程序中调用ajax