XML to javascript array with jQuery

前端 未结 4 1587
面向向阳花
面向向阳花 2021-01-11 18:50

I am new to XML and AJAX and am only a newcomer to Javascript and jQuery. Among other job duties I design our website. A deadline is very near, and the only way I can think

4条回答
  •  余生分开走
    2021-01-11 19:44

    Using jQuery, $.ajax() your XML file, and on success pass retrieved data with each, like:

     var tmpSubject, tmpDate, tmpThumb;
     $.ajax({
                url: '/your_file.xml',
                type: 'GET', 
                dataType: 'xml',
                success: function(returnedXMLResponse){
                    $('item', returnedXMLResponse).each(function(){
                         tmpSubject = $('subject', this).text();
                         tmpDate = $('date', this).text();
                         tmpThumb = $('thumb', this).text();
                        //Here you can do anything you want with those temporary
                        //variables, e.g. put them in some place in your html document
                        //or store them in an associative array
                    })
                }  
            }); 
    

提交回复
热议问题