0

given a XML file inside the public directory like this public -> xml -> restaurant.xml

I want to use an AJAX GET call via JQuery to read the xml nodes in there and append rows to my table with the gathered data.

Question is how would this look in my controller? how can I get into that xml file? So far I have my JQuery code almos done, AJAX url is empty.

JQuery:

var name;
    var half-price;
    var full-price;

    
    $.ajax({
        type: "GET",
        url: "what should I put here?",
        dataType: "xml",
        success: function(xml){
            $(xml).find('starter').each(function(){
                if($(this).attr('name').text() != 'no' && !=''){name = $(this).attr('name').text()};
                if($(this).attr('half-price').text() != 'no' && !=''){price = $(this).attr('half-price').text()};
                if($(this).attr('full-price').text() != 'no' && !=''){price = $(this).attr('full-price').text()};
                
                var menu_row = '<tr class="row">';
                    menu_row += '<td>' + name + '</td>';
                    menu_row += '<td>' + half-price + '</td>';
                    menu_row += '<td>' + full-price + '</td>';
                    menu_row += '</tr>';
    
                $('.entry_table_container[data-link=' + linked_entry + ']').append(menu_row);
            });
        },
        error: function() {
            alert("An error occurred while processing XML file.");
        }
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

My XML file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<!--ENTRANTES-->
<starter name="primero" half-price="no" full-price="no" description="no" featured="no" image="no"></starter>
<starter name="segundo" half-price="no" full-price="no" description="no" featured="no" image="no"></starter>
<starter name="tercero" half-price="no" full-price="no" description="no" featured="no" image="no"></starter>
<starter name="cuarto" half-price="no" full-price="no" description="no" featured="no" image="no"></starter>
<starter name="quinto" half-price="no" full-price="no" description="no" featured="no" image="no"></starter>
<starter name="sexto" half-price="no" full-price="no" description="no" featured="no" image="no"></starter>

0 Answers0