Ajax和Javascript - 获取文件名

时间:2013-09-09 08:36:09

标签: javascript jquery xml ajax xml-parsing

如何获取加载的文件名?我必须把这个而不是标题,但我不知道如何。我试图在xmlParser函数中添加其他参数,但实际上它对我不起作用。这是我的代码:

$(document).ready(function () {
    doAJAX('LoadedFile1.xml');
    doAJAX('LoadedFile2.xml');
});

function doAJAX(url) {
        $.ajax({
        type: "GET",
        url: url,
        dataType: "xml",
        success: xmlParser
    });
}


function xmlParser(xml) {

    $('#load').fadeOut();
    var myDate = new Date();

    var currentdate = new Date(); 
    var n = 
                currentdate.getFullYear()
                + ("0" + (currentdate.getMonth() + 1)).slice(-2)
                + ("0" + currentdate.getDate()).slice(-2)
                + ("0" + currentdate.getHours()).slice(-2)
                + ("0" + currentdate.getMinutes()).slice(-2)
                + ("0" + currentdate.getSeconds()).slice(-2);
    var x = false;
    var y = false;
    $(xml).find("programme").each(function () {

        if ((parseFloat(n) > (parseFloat($(this).attr("start").slice(0,-6)))) && (parseFloat(n) < (parseFloat($(this).attr("stop").slice(0,-6)))))
        {   
            $(".main").append('<div class="header">HEADER</div><div class="programme"><div class="title">' + $(this).find("title").text() + '</div><div class="timec">' + n + '</div><div class="time">' + $(this).attr("start").slice(0,-6) + '</div><div class="time">' + $(this).attr("stop").slice(0,-6) + '</div><div class="description">' + $(this).find("desc").text() + '</div><div class="date">Published ' + $(this).find("category").text() + '</div>');
            x = true;
        } 
        else if ( x == true && y == true)
        {
            $(".main").append('<div class="programme"><div class="title">' + $(this).find("title").text() + '</div><div class="timec">' + n + '</div><div class="time">' + $(this).attr("start").slice(0,-6) + '</div><div class="time">' + $(this).attr("stop").slice(0,-6) + '</div><div class="description">' + $(this).find("desc").text() + '</div><div class="date">Published ' + $(this).find("category").text() + '</div></div>');
            x = false;

        }
        y = true;
        $(".programme").fadeIn(1000);
    });
}

0 个答案:

没有答案