使用AJAX上传XML文件

I've found a mound of questions on SO regarding uploading a file using AJAX although none of them really seem to find my needs.

What I need to do is have a user upload an XML file and have the script run through the XML file and take out the data that is in certain tags in the file and then push the data into a corresponding array which reflects the tag. So say I found a book in an xml, it would push the data into an array NewBooks.

I don't have any experience with PHP, quite honestly its confusing to me. If there is a way without PHP, that would be grand.

reader.onload = function (e) {
        console.log('reading file')
        $(document).ready(function () {
         console.log('analyzing ajax')
            $.ajax({
                type: "GET",
                dataType: "xml",
                success: function (xml) {
                    $(xml).find('book').each(function () {
                        UploadBooks.push($(this).text());
                    });            
                }
            })
        })
   console.log(UploadBooks);
}

That is the code I have although the printed UploadBooks has no elements, even though when I look into the XML file, there are clearly book tags.

Not all browsers can upload files via Ajax. Only those supporting XMLHttpRequest2. Getting that to work with jQuery (as per your example) is going to take some tricks too.

You say you'd rather not use PHP, which would mean no point uploading a file anyway. Check out the HTML5 FileReader API if you want to try and parse the XML file on the client side. You might be able to load the file into a DOM structure to achieve what you're trying to do.