1

如何获取加载的文件名?我必须把这个代替标题,但我不知道怎么做。我试图向 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);
    });
}
4

0 回答 0