Das Beispiel in diesem Artikel beschreibt, wie jQuery das geplante Lesen und Analysieren von XML-Dateien implementiert. Teilen Sie es als Referenz mit allen. Die Details lauten wie folgt:
Hier ist eine Demonstration, wie jQuery regelmäßig XML-Dateien über Ajax liest und analysiert.
Die
xml-Datei lautet wie folgt:
1 2 3 4 | <?xml version= "1.0" ?>
<data>
<page tasks= "1" messages= "3" notifications= "3" />
</data>
|
Nach dem Login kopieren
js-Datei lautet wie folgt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | $(document).ready( function () {
function get_info() {
$.ajax({
type: "GET" ,
url: "page.xml" ,
dataType: "xml" ,
cache: false,
complete: function (doc) {
var tasks = $(doc.responseText).find( "page" ).attr( "tasks" );
var msgs = $(doc.responseText).find( "page" ).attr( "messages" );
var notes = $(doc.responseText).find( "page" ).attr( "notifications" );
if (tasks != $( '#tasks' ).text() ||
msgs != $( '#messages' ).text() ||
notes != $( '#notifications' ).text()) {
document.title = "Facebook" + ' NEW NOTIFICATON' ;
}
$( '#tasks' ).text(tasks);
$( '#messages' ).text(msgs);
$( '#notifications' ).text(notes);
}
});
}
setInterval( function () {
get_info();
}, 5000);
});
|
Nach dem Login kopieren
Ich hoffe, dass dieser Artikel für das JQuery-Programmierungsdesign aller hilfreich sein wird.